-
Notifications
You must be signed in to change notification settings - Fork 0
/
calc.js
28 lines (28 loc) · 1 KB
/
calc.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
function updateScreen(value)
{
const ScreenElement = document.querySelector('.screen'); // query selector is screen coz we wanna display on screen
const currentText = ScreenElement.textContent;
ScreenElement.textContent += value; //adding value to the screen
if(value === "AC")
{
ScreenElement.textContent = '';
}
else if(value == "CE")
{
const newText = currentText.slice(0, -1);
//ScreenElement.textContent is used though currentText has same meaning becoz like python here this is mutable
// any changes to copy will change the original one not cpy
ScreenElement.textContent = newText;
}
else if (value == "=")
{
try
{
ScreenElement.textContent = eval(currentText.replace(/x/g, '*'));
}
catch(e)
{
ScreenElement.textContent = "Syntax Error";
}
}
}