Swathi6 commited on
Commit
d1cfa70
·
verified ·
1 Parent(s): 20e39fe

Create script.js

Browse files
Files changed (1) hide show
  1. script.js +19 -0
script.js ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Function to append the clicked button value to the display
2
+ function appendToDisplay(value) {
3
+ document.getElementById('display').value += value;
4
+ }
5
+
6
+ // Function to clear the display
7
+ function clearDisplay() {
8
+ document.getElementById('display').value = '';
9
+ }
10
+
11
+ // Function to calculate the result of the expression in the display
12
+ function calculateResult() {
13
+ try {
14
+ let result = eval(document.getElementById('display').value);
15
+ document.getElementById('display').value = result;
16
+ } catch (error) {
17
+ document.getElementById('display').value = 'Error';
18
+ }
19
+ }