-
Notifications
You must be signed in to change notification settings - Fork 1
/
js.js
53 lines (51 loc) · 1.66 KB
/
js.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
//grabs the html div with the id of submit, and adds
//a click event listener to it
document.getElementById('submit').addEventListener('click', function() {
//grabs the value of the input with id num1
var number1 = Number(document.getElementById('num1').value);
//grabs the value of the input with id num2
var number2 = Number(document.getElementById('num2').value);
//grabs the value of the input with id operation
var operation = document.getElementById('operation').value;
//grabs the div with the id answer
var answer = document.getElementById('answer');
//this is a conditional check to see if operation is
//equal to the string 'add'. If true, the code inside
//the brackets will be run, if false, it will be skipped
//over. your challenge is to finish the code.
if (operation === 'add') {
//this will add a value to the div
answer.innerHTML = // write your code here
reset();
return;
}
if (operation === 'subtract') {
//this will add a value to the div
answer.innerHTML = // write your code here
reset();
return;
}
if (operation === 'divide') {
//this will add a value to the div
answer.innerHTML = // write your code here
reset();
return;
}
if (operation === 'multiply') {
//this will add a value to the div
answer.innerHTML = // write your code here
reset();
return;
}
if (operation === 'modulo') {
//this will add a value to the div
answer.innerHTML = // write your code here
reset();
return;
}
})
//this simply resets the input fields back to empty
function reset() {
var number1 = document.getElementById('num1').value = ' ';
var number2 = document.getElementById('num2').value = ' ';
}