-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
134 lines (121 loc) · 3.58 KB
/
Copy pathapp.js
File metadata and controls
134 lines (121 loc) · 3.58 KB
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
document.documentElement.className = 't-1';
// function to set a given theme/color-scheme
const setTheme = (themeName) => {
localStorage.setItem('theme', themeName);
document.documentElement.className = themeName;
}
const selectTheme = () => {
if (theme.value === '1') {
setTheme('t-1');
}
if (theme.value === '2') {
setTheme('t-2');
}
if (theme.value === '3') {
setTheme('t-3');
}
}
const theme = document.getElementById('theme');
theme.addEventListener('change', selectTheme);
// Immediately invoked function to set the theme on initial load
(function () {
if (localStorage.getItem('theme') === 't-1') {
setTheme('t-1');
document.getElementById('theme').value = '1';
}
if (localStorage.getItem('theme') === 't-2') {
setTheme('t-2');
document.getElementById('theme').value = '2';
}
if (localStorage.getItem('theme') === 't-3') {
setTheme('t-3');
document.getElementById('theme').value = '3';
}
})();
const outputText = document.querySelector('.output__text');
let userInput = [];
let func = null;
let memo1 = "";
let memo2 = "";
const reset = () => {
userInput = [];
outputText.innerHTML = "";
}
const result = (func) => {
let manipulation = null;
const standartAction = (manipulation) => {
outputText.innerHTML = manipulation;
userInput = [];
memo1 = "";
memo2 = manipulation;
}
switch(func) {
case 'add':
manipulation = Number(memo2) + Number(memo1);
standartAction(manipulation);
break;
case 'substract':
manipulation = Number(memo2) - Number(memo1);
standartAction(manipulation);
break;
case 'multiply':
manipulation = Number(memo2) * Number(memo1);
standartAction(manipulation);
break;
case 'devide':
manipulation = Number(memo2) / Number(memo1);
standartAction(manipulation);
break;
}
}
const inputFunc = (value) => {
const functionality = (value) => {
if(func === null && memo2 === "") {
func = value;
memo2 = memo1;
reset();
} else {
result(func);
func = value;
}
}
switch(true) {
case (typeof value === 'number'):
userInput.push(value);
outputText.innerHTML = userInput.join("");
memo1 = userInput.join("");
break;
case (value === 'del'): //&& userInput.length > 0
userInput.pop();
outputText.innerHTML = userInput.join("");
memo1 = userInput.join("");
if(memo2) {
memo2 = memo2.toString();
memo2 = memo2.slice(0, -1)
outputText.innerHTML = memo2;
}
break;
case (value === 'decimal'):
userInput.push(".");
outputText.innerHTML = userInput.join("");
memo1 = userInput.join("");
break;
case (value === 'reset'):
reset();
memo1 = "";
memo2 = "";
func = null;
break;
case (value === 'result'):
if(func !== null) {
result(func);
func = null;
} else {
outputText.innerHTML = 'Please input value';
}
break;
case (value === 'add' || value === 'substract' || value === 'multiply' || value === 'devide'):
functionality(value);
break;
}
}