-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
69 lines (43 loc) · 1.45 KB
/
main.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
68
69
function handlerSubmit(event) {
event.preventDefault()
const chosenOption = document.querySelector('input[name = "chosen-option"]:checked')
console.log(chosenOption)
const inputSum = event.target[2]
const inputSubt = event.target[3]
const inputMultp = event.target[4]
const inputDiv = event.target[5]
const result = event.target[6]
const buttonClear = event.target[8]
const val1 = parseFloat(event.target[0].value)
const val2 = parseFloat(event.target[1].value)
if(chosenOption == inputSum) {
const sum = () => {
return val1 + val2
}
result.value = sum()
}else if (chosenOption == inputSubt){
const subt = () => {
return val1 - val2
}
result.value = subt()
}else if (chosenOption == inputMultp){
const multip = () => {
return val1 * val2
}
result.value = multip()
}else if (chosenOption == inputDiv){
const divd = () => {
return val1 / val2
}
result.value = divd()
}
function clearFields() {
event.target[0].value = ''
event.target[1].value = ''
event.target[6].value = ''
if(chosenOption){
chosenOption.checked = false
}
}
buttonClear.addEventListener('click', clearFields)
}