-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscripts.js
More file actions
89 lines (88 loc) · 2.93 KB
/
scripts.js
File metadata and controls
89 lines (88 loc) · 2.93 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
var buttons1 = document.querySelectorAll(".non-oper");
var buttons2 = document.querySelectorAll(".oper");
var i;
//light when hover
for (i = 0; i < buttons1.length; i++) {
//hover - lighter
buttons1[i].addEventListener('mouseover', function(event) {
event.target.style.backgroundColor = '#f2f2f3';
});
//unhover - normL color
buttons1[i].addEventListener('mouseout', function(event) {
event.target.style.backgroundColor = '#d8d9db';
});
//pressed - darker
buttons1[i].addEventListener('mousedown', function(event) {
event.target.style.backgroundColor = '#bdbec2';
});
//unpressed - lighter
buttons1[i].addEventListener('mouseup', function(event) {
event.target.style.backgroundColor = '#f2f2f3';
});
}
////////////////////////////////////////////
//same with orange ones
for (i = 0; i < buttons2.length; i++) {
buttons2[i].addEventListener('mouseover', function(event) {
event.target.style.backgroundColor = '#e4a867';
});
buttons2[i].addEventListener('mouseout', function(event) {
event.target.style.backgroundColor = '#df974c';
});
buttons2[i].addEventListener('mousedown', function(event) {
event.target.style.backgroundColor = '#d98226';
});
buttons2[i].addEventListener('mouseup', function(event) {
event.target.style.backgroundColor = '#e4a867';
});
}
////////////////////////////////////////////////////////////
//number buttons
var nums = document.querySelectorAll(".num");
var input = document.querySelector(".input");
for (i = 0; i < nums.length; i++) {
nums[i].addEventListener('click', function(event) {
if (input.innerText === '0') {
input.innerText = event.target.innerText;
} else {
input.innerText = input.innerText + `${event.target.innerText}`;
}
});
};
//delete and reset buttons
var c = document.querySelector(".reset");
c.addEventListener('click', function() {
input.innerText = '0';
});
var del = document.querySelector(".delete");
del.addEventListener('click', function() {
if (input.innerText.length === 1) {
input.innerText = '0';
} else {
input.innerText = input.innerText.slice(0, (input.innerText.length - 1))
}
});
//evaluation of input
var string = '';
var operators = document.querySelectorAll(".oper");
var symbol;
for (i = 0; i < operators.length - 1; i++) {
operators[i].addEventListener('click', function(event) {
if (event.target.innerText === '÷') {
symbol = '/';
}
else if (event.target.innerText === '×') {
symbol = '*';
}
else {
symbol = `${event.target.innerText}`;
}
string = string + input.innerText + symbol;
input.innerText = '0';
});
};
operators[operators.length - 1].addEventListener('click', function(event) {
string = string + input.innerText;
input.innerText = eval(string);
string = '';
});