-
Notifications
You must be signed in to change notification settings - Fork 0
/
calculator.js
67 lines (52 loc) · 1.39 KB
/
calculator.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
let readline = require('readline-sync');
const add = (a, b) => {
return a + b;
};
const sub = (a, b) => {
return a - b;
};
const mult = (a, b) => {
return a * b;
};
const div = (a, b) => {
return a / b;
};
let array = '';
const whichOne = () => {
let result = 0;
for (let i = 0; i < array.length; i++) {
if (i > 0 && array[i] === '+') {
array = array.split(/[+*-/]/g);
result = add(Number(array[0]), Number(array[1]));
console.log('Eredmény:', result);
return result;
}
if (i > 0 && array[i] === '-') {
array = array.split(/[+*-/]/g);
result = sub(Number(array[0]), Number(array[1]));
console.log('Eredmény:', result);
return result;
}
if (i > 0 && array[i] === '*') {
array = array.split(/[+*-/]/g);
result = mult(Number(array[0]), Number(array[1]));
console.log('Eredmény:', result);
return result;
}
if (i > 0 && array[i] === '/') {
array = array.split(/[+*-/]/g);
result = div(Number(array[0]), Number(array[1]));
console.log('Eredmény:', result);
return result;
} else {
}
}
console.log('Gondold újra az életed');
};
// array = array.split(/[+*-/]/g);
// array = array.split(/[+*-/]/g);
console.log('Üdv a számológépben.');
console.log('Kérlek add meg az elvégzendő műveletet');
array = readline.question();
whichOne();
// console.log(array);