forked from Degman1/326GitWorkflowLab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscripts.js
52 lines (36 loc) · 962 Bytes
/
scripts.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
let display = document.getElementById('display');
// Append number or operator to the display
function appendToDisplay(value) {
display.value += value;
}
// Clear the entire display
function clearDisplay() {
display.value = '';
}
// Delete the last character from the display
function deleteLast() {
display.value = display.value.slice(0, -1);
}
// Calculate and show the result
function calculateResult() {
try {
display.value = eval(display.value);
} catch (error) {
display.value = 'Error';
}
}
function runSquareRoot() {
const v = calculateSquareRoot(display.value);
display.value = v;
}
function runSquare() {
// Hint: Use exponentiation
const v = calculateSquare(display.value);
display.value = v;
}
function runReciprocal() {
// Hint: Reciprocal is 1/x
const v = calculateReciprocal(display.value);
display.value = v;
}
// TODO: Implement run your functions here