2024-04-21 16:41:13 +00:00
|
|
|
let timerRunning = false;
|
|
|
|
let startTime;
|
|
|
|
let elapsedTime = 0;
|
2024-04-21 17:08:19 +00:00
|
|
|
let ghostGameRunning = false;
|
|
|
|
let ghostTimer;
|
|
|
|
let ghostAppearTime;
|
|
|
|
document.getElementById('startGhostGame').addEventListener('click', function() {
|
|
|
|
ghostGameRunning = true;
|
|
|
|
document.getElementById('ghostDisplay').textContent = '';
|
|
|
|
document.getElementById('ghostResults').textContent = '';
|
|
|
|
document.getElementById('bustGhost').style.display = 'none';
|
|
|
|
let randomTime = Math.random() * 10000; // Random time within 10 seconds
|
|
|
|
ghostTimer = setTimeout(function() {
|
|
|
|
document.getElementById('ghostDisplay').textContent = '👻';
|
|
|
|
ghostAppearTime = Date.now();
|
|
|
|
document.getElementById('bustGhost').style.display = 'inline';
|
|
|
|
}, randomTime);
|
2024-04-21 16:41:13 +00:00
|
|
|
});
|
2024-04-21 17:08:19 +00:00
|
|
|
document.getElementById('bustGhost').addEventListener('click', function() {
|
|
|
|
if (!ghostAppearTime) {
|
|
|
|
document.getElementById('ghostResults').textContent = 'Too early! You lose!';
|
|
|
|
clearTimeout(ghostTimer);
|
2024-04-21 17:00:20 +00:00
|
|
|
} else {
|
2024-04-21 17:08:19 +00:00
|
|
|
let reactionTime = Date.now() - ghostAppearTime;
|
|
|
|
document.getElementById('ghostResults').textContent = `Reaction Time: ${reactionTime} ms`;
|
2024-04-21 17:00:20 +00:00
|
|
|
}
|
2024-04-21 17:08:19 +00:00
|
|
|
ghostGameRunning = false;
|
|
|
|
document.getElementById('bustGhost').style.display = 'none';
|
2024-04-21 17:00:20 +00:00
|
|
|
});
|
2024-04-22 14:54:21 +00:00
|
|
|
|
|
|
|
function jjm(){
|
2024-04-21 16:41:13 +00:00
|
|
|
timerHistory.push(time);
|
|
|
|
const newTime = document.createElement('li');
|
|
|
|
newTime.textContent = `Time: ${time} ms`;
|
|
|
|
historyList.appendChild(newTime);
|
|
|
|
}
|
2024-04-21 17:00:20 +00:00
|
|
|
|
2024-04-21 17:12:02 +00:00
|
|
|
function recordTime(time) {
|
|
|
|
const historyList = document.getElementById('historyList');
|
2024-04-21 17:00:20 +00:00
|
|
|
const newTime = document.createElement('li');
|
2024-04-21 17:12:02 +00:00
|
|
|
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);
|
|
|
|
}
|
2024-04-22 14:54:21 +00:00
|
|
|
});
|