-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
63 lines (54 loc) · 1.84 KB
/
script.js
File metadata and controls
63 lines (54 loc) · 1.84 KB
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
57
58
59
60
61
62
63
let memory = 0; // Initialize memory variable
// Function to toggle between light and dark themes
function toggleTheme() {
document.body.classList.toggle('dark-theme');
}
// Function to clear the display
function clearDisplay() {
document.getElementById('display').value = '';
}
// Function to delete the last character from the display
function deleteLast() {
var display = document.getElementById('display');
display.value = display.value.slice(0, -1);
}
// Function to append characters to the display
function appendCharacter(char) {
var display = document.getElementById('display');
// Add closing parenthesis for specific functions
if (char === 'Math.sin(' || char === 'Math.cos(' || char === 'Math.tan(' || char === 'Math.log(' || char === 'Math.log10(') {
display.value += char + ')';
} else {
display.value += char;
}
}
// Function to calculate and display the result
function calculate() {
var display = document.getElementById('display');
try {
// Replace percentage symbol with division by 100
var expression = display.value.replace(/%/g, '/100');
display.value = eval(expression);
} catch (e) {
display.value = 'Error'; // Display error for invalid expressions
}
}
// Function to clear the memory
function memoryClear() {
memory = 0;
}
// Function to recall the value stored in memory
function memoryRecall() {
var display = document.getElementById('display');
display.value = memory;
}
// Function to add the current display value to memory
function memoryAdd() {
var display = document.getElementById('display');
memory += parseFloat(display.value);
}
// Function to subtract the current display value from memory
function memorySubtract() {
var display = document.getElementById('display');
memory -= parseFloat(display.value);
}