- Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathscript.js
More file actions
Latest commit
30 lines (21 loc) · 753 Bytes
/
Copy pathscript.js
File metadata and controls
30 lines (21 loc) · 753 Bytes
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
varinput=document.getElementById("display");
//script to detect if enter button is clicked to evaluate the result
input.addEventListener("keyup",function(event){
// Number 13 is the "Enter" key on the keyboard
if(event.keyCode==13){
// Trigger the button element with a click
document.getElementById("equal").click();
}
});
// Function to calculate the result
functioncalculate(operation){
letresult;
try{
result=eval(operation);
}catch(error){}
if(result===0||isFinite(result)&&Boolean(result)){
document.getElementById('display').value=result;
}else{
document.getElementById('display').value='Invalid operation';
}
}