-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
79 lines (62 loc) · 2.24 KB
/
Copy pathapp.js
File metadata and controls
79 lines (62 loc) · 2.24 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
window.addEventListener('DOMContentLoaded', function() {
const profileImg = document.getElementById('profile-img');
const userPic = document.getElementById('user-pic');
// Show username in the header
const userNameElem = document.getElementById('user-name');
const username = localStorage.getItem('currentUser') || 'User';
if (userNameElem) {
userNameElem.textContent = username;
}
// Load saved image if it exists
const savedImg = localStorage.getItem('profileImg');
if (savedImg) {
profileImg.src = savedImg;
}
// Click image to open file picker
profileImg.addEventListener('click', function() {
userPic.click();
});
// When user selects a new image, update and save to localStorage
userPic.addEventListener('change', function(event) {
const file = event.target.files[0];
if (file) {
const reader = new FileReader();
reader.onload = function(e) {
profileImg.src = e.target.result;
localStorage.setItem('profileImg', e.target.result);
};
reader.readAsDataURL(file);
}
});
});
function checkAnswer(qNum, correctAnswer) {
const input = document.getElementById('answer' + qNum).value;
const result = document.getElementById('result' + qNum);
if (parseInt(input) === correctAnswer) {
result.innerHTML = '✅ Correct!';
result.className = 'correct';
} else {
result.innerHTML = '❌ Try again';
result.className = 'wrong';
}
}
const tapCircle = document.querySelector('.tap-circle');
const balanceElem = document.querySelector('.amount');
// Get the current username
const username = localStorage.getItem('currentUser') || 'User';
// Load balance for this user or start at 0
let balance = parseFloat(localStorage.getItem(username + '_balance')) || 0;
// Function to update the balance display
function updateBalance() {
balanceElem.textContent = `₦${balance.toFixed(2)}`;
}
// On tap, add ₦0.02 and update
if (tapCircle) {
tapCircle.addEventListener('click', function() {
balance = Math.round((balance + 0.02) * 100) / 100;
updateBalance();
localStorage.setItem(username + '_balance', balance);
});
}
// Show the balance on page load
updateBalance();