-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerator.js
47 lines (37 loc) · 1.15 KB
/
generator.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
const fs = require('fs')
const path = require('path')
const filePath = path.resolve(__dirname, './myFirstCalculator.js')
const minNum = 0
const maxNum = 50
const signs = ['+', '-', '/', '*']
let output = `
#!/usr/bin/env node
const readline = require('readline')
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
})
rl.write('Welcome to this calculator!\\n')
rl.write('It can add, subtract, multiply and divide whole numbers from ${minNum} to ${maxNum}\\n')
rl.question('Please choose your first number: ', a =>
rl.question('What do you want to do? +, -, /, or *: ', sign =>
rl.question('Please choose your second number: ', b => {
`
for (let sign of signs) {
for (let a = minNum; a <= maxNum; a++) {
for (let b = minNum; b <= maxNum; b++) {
const value = eval(a + sign + b)
output += ` if (a == ${a} && sign == '${sign}' && b == ${b}) {\n`
output += ` rl.write('${a} ${sign} ${b} = ${value}\\n')\n`
output += ` }\n`
}
}
}
output += `
rl.write('Thanks for using this calculator, goodbye :)\\n')
rl.close()
})
)
)
`
fs.writeFileSync(filePath, output.trim())