-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
44 lines (36 loc) · 1.07 KB
/
app.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
const resultElement = document.getElementById('result')
const input1 = document.getElementById('input1')
const input2 = document.getElementById('input2')
const submitBtn = document.getElementById('submit')
const plusBtn = document.getElementById ('plus')
const minusBtn = document.getElementById('minus')
plusBtn.onclick = function() {
action = "+"
}
minusBtn.onclick = function() {
action = "-"
}
function printResult (result){
if(result < 0) [
resultElement.style.color = 'red'
]
else {
resultElement.style.color = 'green'
}
resultElement.textContent = result
}
function computeNumbersWithAction(inp1,inp2, actionSymbol) {
const num1 = Number(inp1.value)
const num2 = Number(inp2.value)
// if(actionSymbol == '+') {
// return num1 + num2
// }
// if (actionSymbol == '-') {
// return num1 - num2
// }
return actionSymbol == '+' ? num1 + num2 : num1 - num2
}
submitBtn.onclick = function (){
const result = computeNumbersWithAction(input1, input2, action)
printResult(result)
}