-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
92 lines (76 loc) · 2.57 KB
/
script.js
File metadata and controls
92 lines (76 loc) · 2.57 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
let loggedIn = false;
let isAdmin = false;
let calculationHistory = [];
function login() {
const username = document.getElementById('username').value;
const password = document.getElementById('password').value;
// Simulated login check
if (username === 'user' && password === 'password') {
loggedIn = true;
showCalculator();
} else if (username === 'admin' && password === 'adminpassword') {
isAdmin = true;
showCalculator();
showAdminPanel();
} else {
alert('Invalid username or password');
}
}
function showCalculator() {
document.getElementById('login').classList.add('hidden');
document.getElementById('calculator').classList.remove('hidden');
}
function showAdminPanel() {
const adminPanel = document.createElement('div');
adminPanel.id = 'admin';
const disableLabel = document.createElement('label');
disableLabel.innerHTML = 'Disable User:';
const disableSelect = document.createElement('select');
disableSelect.id = 'disableSelect';
const disableButton = document.createElement('button');
disableButton.innerHTML = 'Disable';
disableButton.onclick = disableUser;
const userOption = document.createElement('option');
userOption.value = 'user';
userOption.innerHTML = 'User';
disableSelect.appendChild(userOption);
disableLabel.appendChild(disableSelect);
adminPanel.appendChild(disableLabel);
adminPanel.appendChild(disableButton);
document.body.appendChild(adminPanel);
}
function disableUser() {
const selectedUser = document.getElementById('disableSelect').value;
// Perform actions to disable the selected user
alert('User ' + selectedUser + ' disabled');
}
function appendNumber(number) {
document.getElementById('result').value += number;
}
function appendOperator(operator) {
document.getElementById('result').value += operator;
}
function calculate() {
const expression = document.getElementById('result').value;
const result = eval(expression);
document.getElementById('result').value = result;
if (document.getElementById('saveHistory').checked) {
calculationHistory.push(expression + ' = ' + result);
}
}
function clearResult() {
document.getElementById('result').value = '';
}
function saveCalculation() {
if (loggedIn) {
const saveHistory = document.getElementById('saveHistory').checked;
if (saveHistory) {
// Save calculation history
alert('Calculation history saved');
} else {
alert('Calculation not saved');
}
} else {
alert('Please log in first');
}
}