-
Notifications
You must be signed in to change notification settings - Fork 1
/
script.js
45 lines (35 loc) · 1.31 KB
/
script.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
// I have used jquery here instead of using javascript. DOM manipulation is easy with jquery.
$( document ).ready(function() { // it needs a ready function to start.
var a = 0;
var add = function(valueToAdd) {
a += valueToAdd;
document.getElementById('value').innerHTML = a;
} //add button logic
var reset = function() {
a = 0;
document.getElementById('value').innerHTML = 0;
} //reset button logic
var subtract = function() {
a =a-1;
if(a>=1)
document.getElementById('value').innerHTML = a;
else{
a = 0;
document.getElementById('value').innerHTML = 0;
}
} // subtract buttion logic
// selected html documents using jquery. which uses id or class to pick DOM elements.
var addButton = document.querySelector("#add");
var resetButton = document.querySelector("#reset");
var subtractButton = document.querySelector("#subtract");
//on click events
addButton.addEventListener("click", function() {
add(1);
})
resetButton.addEventListener("click", function() {
reset();
})
subtractButton.addEventListener("click", function() {
subtract(1);
})
});