Fix bugs in script.js
.
This commit is contained in:
parent
20483d4c40
commit
6d05755825
1 changed files with 43 additions and 22 deletions
|
@ -1,6 +1,10 @@
|
|||
let timerRunning = false;
|
||||
let startTime;
|
||||
let elapsedTime = 0;
|
||||
let timerHistory = [];
|
||||
let challengeRunning = false;
|
||||
let challengeStartTime;
|
||||
let challengeTimes = [];
|
||||
let ghostGameRunning = false;
|
||||
let ghostTimer;
|
||||
let ghostAppearTime;
|
||||
|
@ -28,29 +32,46 @@ document.getElementById('bustGhost').addEventListener('click', function() {
|
|||
document.getElementById('bustGhost').style.display = 'none';
|
||||
});
|
||||
|
||||
function jjm(){
|
||||
timerHistory.push(time);
|
||||
const newTime = document.createElement('li');
|
||||
newTime.textContent = `Time: ${time} ms`;
|
||||
historyList.appendChild(newTime);
|
||||
}
|
||||
const timerButton = document.getElementById('timerButton');
|
||||
const historyList = document.getElementById('historyList');
|
||||
const challengeButton = document.getElementById('challengeButton');
|
||||
timerButton.addEventListener('click', function() {
|
||||
if (!timerRunning) {
|
||||
startTime = Date.now() - elapsedTime;
|
||||
timerRunning = true;
|
||||
timerButton.textContent = 'Stop Timer';
|
||||
} else {
|
||||
elapsedTime = Date.now() - startTime;
|
||||
timerRunning = false;
|
||||
timerButton.textContent = 'Start Timer';
|
||||
recordTime(elapsedTime);
|
||||
}
|
||||
});
|
||||
|
||||
challengeButton.addEventListener('click', function() {
|
||||
if (!challengeRunning) {
|
||||
challengeStartTime = Date.now();
|
||||
challengeRunning = true;
|
||||
challengeButton.textContent = 'Tap at 2 seconds';
|
||||
} else {
|
||||
let tapTime = Date.now();
|
||||
let interval = tapTime - challengeStartTime;
|
||||
challengeTimes.push(interval);
|
||||
challengeRunning = false;
|
||||
challengeButton.textContent = '⏱️ 2-Second Challenge ⏱️';
|
||||
recordChallengeTime(interval);
|
||||
}
|
||||
});
|
||||
|
||||
function recordTime(time) {
|
||||
const historyList = document.getElementById('historyList');
|
||||
const newTime = document.createElement('li');
|
||||
newTime.textContent = `Time: ${time} ms`;
|
||||
historyList.appendChild(newTime);
|
||||
timerHistory.push(time);
|
||||
const newTime = document.createElement('li');
|
||||
newTime.textContent = `Time: ${time} ms`;
|
||||
historyList.appendChild(newTime);
|
||||
}
|
||||
|
||||
document.getElementById('timerButton').addEventListener('click', function() {
|
||||
if (!timerRunning) {
|
||||
startTime = Date.now();
|
||||
timerRunning = true;
|
||||
this.textContent = 'Stop Timer';
|
||||
} else {
|
||||
elapsedTime = Date.now() - startTime;
|
||||
timerRunning = false;
|
||||
this.textContent = 'Start Timer';
|
||||
recordTime(elapsedTime);
|
||||
}
|
||||
});
|
||||
function recordChallengeTime(time) {
|
||||
const newTime = document.createElement('li');
|
||||
newTime.textContent = `Attempt: ${time} ms - ${Math.abs(2000 - time)} ms off`;
|
||||
resultsList.appendChild(newTime);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue