From 833630d49486c5c778a11e6457c2ea8b3dd1ddb6 Mon Sep 17 00:00:00 2001 From: 287931262zjh <287931262@qq.com> Date: Tue, 1 Mar 2022 17:33:30 +0800 Subject: [PATCH] 3.1 --- .../calculate.js" | 16 ++++++++++++++ .../module_count.js" | 22 +++++++++++++++++++ .../test.js" | 13 +++++++++++ .../test1.js" | 9 ++++++++ .../fileplay.js" | 17 ++++++++++++++ .../writefile.js" | 8 +++++++ .../100.txt" | 1 + .../com.txt" | 1 + .../demo${i}.txt" | 1 + .../read.js" | 14 ++++++++++++ 10 files changed, 102 insertions(+) create mode 100644 "\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" create mode 100644 "\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" create mode 100644 "\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" create mode 100644 "\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" create mode 100644 "\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" create mode 100644 "\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" create mode 100644 "\345\274\240\346\235\260\345\215\216/03\346\226\207\344\273\266\350\257\273\345\217\226/100.txt" create mode 100644 "\345\274\240\346\235\260\345\215\216/03\346\226\207\344\273\266\350\257\273\345\217\226/com.txt" create mode 100644 "\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" create mode 100644 "\345\274\240\346\235\260\345\215\216/03\346\226\207\344\273\266\350\257\273\345\217\226/read.js" 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 0000000..093c01b --- /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 0000000..aed8e77 --- /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 0000000..1fa5390 --- /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 0000000..af4f467 --- /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 0000000..8d9f034 --- /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 0000000..526c5f9 --- /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 0000000..890b080 --- /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 0000000..d0817af --- /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 0000000..e7fab1c --- /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 0000000..5d4a33a --- /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 -- Gitee