diff --git "a/\345\274\240\346\235\260\345\215\216/01\346\250\241\345\235\227\345\214\226\345\256\236\347\216\260\345\212\240\345\207\217\344\271\230\351\231\244/calculate.js" "b/\345\274\240\346\235\260\345\215\216/01\346\250\241\345\235\227\345\214\226\345\256\236\347\216\260\345\212\240\345\207\217\344\271\230\351\231\244/calculate.js" new file mode 100644 index 0000000000000000000000000000000000000000..093c01b0d76b2ea244dfc059ff03e670b6f804b9 --- /dev/null +++ "b/\345\274\240\346\235\260\345\215\216/01\346\250\241\345\235\227\345\214\226\345\256\236\347\216\260\345\212\240\345\207\217\344\271\230\351\231\244/calculate.js" @@ -0,0 +1,16 @@ +module.exports = + function add (x,y){ + return parseInt(x) + parseInt(y); + } + + function subtract (x,y){ + return parseInt(x) - parseInt(y); +} + +function multiply (x,y){ + return parseInt(x) * parseInt(y); +} + +function divide (x,y){ + return parseInt(x) / parseInt(y); +} \ No newline at end of file diff --git "a/\345\274\240\346\235\260\345\215\216/01\346\250\241\345\235\227\345\214\226\345\256\236\347\216\260\345\212\240\345\207\217\344\271\230\351\231\244/module_count.js" "b/\345\274\240\346\235\260\345\215\216/01\346\250\241\345\235\227\345\214\226\345\256\236\347\216\260\345\212\240\345\207\217\344\271\230\351\231\244/module_count.js" new file mode 100644 index 0000000000000000000000000000000000000000..aed8e775664b687996290e63cffe2915ac9f8816 --- /dev/null +++ "b/\345\274\240\346\235\260\345\215\216/01\346\250\241\345\235\227\345\214\226\345\256\236\347\216\260\345\212\240\345\207\217\344\271\230\351\231\244/module_count.js" @@ -0,0 +1,22 @@ +var count = { + add: function add( x , y ) { + return x + y; + }, + subtract:function subtract ( x , y){ + return x - y; + }, + multiply:function multiply ( x ,y ){ + return x * y; + }, + divide:function divide ( x , y ){ + return x / y; + } +} + +function handle( x , y , symbol ){ + if(isNaN(x)|| isNaN(y) ){ + throw Error("请输入数值"); + } + return count[symbol](x,y); +} +module.exports.handle = handle; \ No newline at end of file diff --git "a/\345\274\240\346\235\260\345\215\216/01\346\250\241\345\235\227\345\214\226\345\256\236\347\216\260\345\212\240\345\207\217\344\271\230\351\231\244/test.js" "b/\345\274\240\346\235\260\345\215\216/01\346\250\241\345\235\227\345\214\226\345\256\236\347\216\260\345\212\240\345\207\217\344\271\230\351\231\244/test.js" new file mode 100644 index 0000000000000000000000000000000000000000..1fa5390cf27a647dff08d8e5be31e9011c99a087 --- /dev/null +++ "b/\345\274\240\346\235\260\345\215\216/01\346\250\241\345\235\227\345\214\226\345\256\236\347\216\260\345\212\240\345\207\217\344\271\230\351\231\244/test.js" @@ -0,0 +1,13 @@ +let cal = require('./calculate'); +let add =(41+42); +console.log(add); + +let subtract =(5-9); +console.log(subtract); + +let multiply =(3*6); +console.log(multiply); + +let divide =(35/5); +console.log(divide); + diff --git "a/\345\274\240\346\235\260\345\215\216/01\346\250\241\345\235\227\345\214\226\345\256\236\347\216\260\345\212\240\345\207\217\344\271\230\351\231\244/test1.js" "b/\345\274\240\346\235\260\345\215\216/01\346\250\241\345\235\227\345\214\226\345\256\236\347\216\260\345\212\240\345\207\217\344\271\230\351\231\244/test1.js" new file mode 100644 index 0000000000000000000000000000000000000000..af4f46766cabff7a7b420575e73d18a313d4ac91 --- /dev/null +++ "b/\345\274\240\346\235\260\345\215\216/01\346\250\241\345\235\227\345\214\226\345\256\236\347\216\260\345\212\240\345\207\217\344\271\230\351\231\244/test1.js" @@ -0,0 +1,9 @@ +let count =require('./module_count'); +try{ + console.log(count.handle(9,3,'add')); + console.log(count.handle(6,4,'subtract')); + console.log(count.handle(5,4,'multiply')); + console.log(count.handle(10,2,'divide')); +}catch(error){ + console.log(error.message); +} \ No newline at end of file diff --git "a/\345\274\240\346\235\260\345\215\216/02\345\220\214\345\274\202\346\255\245\345\206\231\345\205\245/fileplay.js" "b/\345\274\240\346\235\260\345\215\216/02\345\220\214\345\274\202\346\255\245\345\206\231\345\205\245/fileplay.js" new file mode 100644 index 0000000000000000000000000000000000000000..8d9f034fbb80d75b4821b9f61d93225c0559ab48 --- /dev/null +++ "b/\345\274\240\346\235\260\345\215\216/02\345\220\214\345\274\202\346\255\245\345\206\231\345\205\245/fileplay.js" @@ -0,0 +1,17 @@ +//写一段代码,可以指定的创建多个文件,文件名中要有序号,写入的内容可以随机 +let fs =require("fs"); +let fd=[] +function create(num){ + if(isNaN(num)){ + throw new Error("请输入数字") + }else{ + for(let i = 1; i < num ; i++){ + fd[i] = fs.openSync('${i}' , "w"); + fs.writeSync(fdp[i],'${Math.random()}'); + fs.closeSync(fn[i]) + } + } +} +module.exports={ + create:create +} \ No newline at end of file diff --git "a/\345\274\240\346\235\260\345\215\216/02\345\220\214\345\274\202\346\255\245\345\206\231\345\205\245/writefile.js" "b/\345\274\240\346\235\260\345\215\216/02\345\220\214\345\274\202\346\255\245\345\206\231\345\205\245/writefile.js" new file mode 100644 index 0000000000000000000000000000000000000000..526c5f97dd84b1e84500b442d2a88bbae7e4cf61 --- /dev/null +++ "b/\345\274\240\346\235\260\345\215\216/02\345\220\214\345\274\202\346\255\245\345\206\231\345\205\245/writefile.js" @@ -0,0 +1,8 @@ +//调用fs +let cre = require("./fileplay"); +try{ + cre.create(5) +}catch(error){ + console.log(error.message); + +} \ No newline at end of file diff --git "a/\345\274\240\346\235\260\345\215\216/03\346\226\207\344\273\266\350\257\273\345\217\226/100.txt" "b/\345\274\240\346\235\260\345\215\216/03\346\226\207\344\273\266\350\257\273\345\217\226/100.txt" new file mode 100644 index 0000000000000000000000000000000000000000..890b080063761dad74d01987eb9bced17776e6f8 --- /dev/null +++ "b/\345\274\240\346\235\260\345\215\216/03\346\226\207\344\273\266\350\257\273\345\217\226/100.txt" @@ -0,0 +1 @@ +0.9324421358974855 \ No newline at end of file diff --git "a/\345\274\240\346\235\260\345\215\216/03\346\226\207\344\273\266\350\257\273\345\217\226/com.txt" "b/\345\274\240\346\235\260\345\215\216/03\346\226\207\344\273\266\350\257\273\345\217\226/com.txt" new file mode 100644 index 0000000000000000000000000000000000000000..d0817afc4a8edafe7464aa0442a80434c65b48ce --- /dev/null +++ "b/\345\274\240\346\235\260\345\215\216/03\346\226\207\344\273\266\350\257\273\345\217\226/com.txt" @@ -0,0 +1 @@ +0.926815973534229${ason}${ason}${ason}${ason}${ason}${ason}${ason}${ason}${ason}${ason}${ason}${ason}${ason}${ason}${ason}${ason}${ason}${ason}${ason}${ason}${ason}${ason}${ason}${ason}${ason}${ason}${ason}${ason}${ason}${ason}${ason}${ason}${ason}${ason}${ason}${ason}${ason}${ason}${ason}${ason}${ason}${ason}${ason}${ason}${ason}${ason}${ason}${ason}${ason}${ason}${ason}${ason}${ason}${ason}${ason}${ason}${ason}${ason}${ason}${ason}${ason}${ason}${ason}${ason}${ason}${ason}${ason}${ason}${ason}${ason}${ason}${ason}${ason}${ason}${ason}${ason}${ason}${ason}${ason}${ason}${ason}${ason}${ason}${ason}${ason}${ason}${ason}${ason}${ason}${ason}${ason}${ason}${ason}${ason}${ason}${ason}${ason}${ason}${ason}${ason} \ No newline at end of file diff --git "a/\345\274\240\346\235\260\345\215\216/03\346\226\207\344\273\266\350\257\273\345\217\226/demo${i}.txt" "b/\345\274\240\346\235\260\345\215\216/03\346\226\207\344\273\266\350\257\273\345\217\226/demo${i}.txt" new file mode 100644 index 0000000000000000000000000000000000000000..e7fab1c29e29c1769a2745002348cdbf6bae55ad --- /dev/null +++ "b/\345\274\240\346\235\260\345\215\216/03\346\226\207\344\273\266\350\257\273\345\217\226/demo${i}.txt" @@ -0,0 +1 @@ +${ason} \ No newline at end of file diff --git "a/\345\274\240\346\235\260\345\215\216/03\346\226\207\344\273\266\350\257\273\345\217\226/read.js" "b/\345\274\240\346\235\260\345\215\216/03\346\226\207\344\273\266\350\257\273\345\217\226/read.js" new file mode 100644 index 0000000000000000000000000000000000000000..5d4a33a8326bcc07f8c1fa134c7bcaded4ad407c --- /dev/null +++ "b/\345\274\240\346\235\260\345\215\216/03\346\226\207\344\273\266\350\257\273\345\217\226/read.js" @@ -0,0 +1,14 @@ +//作业: +//1.先创建100个文件,文件内容自便,创建完以后呢,读取每一个文件,并且把每一个文件的内容拼接起来 +//创建100个文件 +let fs = require('fs'); +for(let i = 1 ; i <= 100 ;i++){ + let ason = Math.ceil(Math.random()*10) + let fn =fs.openSync('./com.txt','a') + let fd = fs.openSync('./demo${i}.txt',"w"); + fs.writeSync(fd,'${ason}'); + fs.writeSync(fn,'${ason}'); + fs.closeSync(fd); +} +let buffer = fs.readFileSync("./com.txt",{flag:'r',encoding:'utf8'}); +console.log(buffer.toString()); \ No newline at end of file