-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalculator.js
56 lines (44 loc) · 1.39 KB
/
calculator.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
(function () {
let screen = document.querySelector('.screen');
let boutons = document.querySelectorAll('.btn');
let clear = document.querySelector('.btn-clear');
let egality = document.querySelector('.btn-equal');
let racine = document.querySelector('.racine')
let pourcent = document.querySelector('.pourcent')
let plus_minus = document.querySelector('.plus_minus')
boutons.forEach(function (button) {
button.addEventListener('click', function (e) {
let value = e.target.dataset.num;
screen.value += value;
})
});
// egality button //
egality.addEventListener('click', function(e){
if(screen.value === ''){
screen.value = "Please enter";
}
else{
let answer = eval(screen.value);
screen.value = answer;
}
})
// clear button //
// racine button //
racine.addEventListener('click', Racin)
function Racin(){
let answer = Math.sqrt(screen.value);
screen.value = answer;
}
// percent button //
pourcent.addEventListener('click', Percent)
function Percent(){
let answer = (screen.value)/100;
screen.value = answer;
}
// plus_minus button //
plus_minus.addEventListener('click', Minus)
function Minus(){
let answer = -(screen.value);
screen.value = answer;
}
})();