Click Speed Test - HTML
Click Speed Test - HTML
DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Click Speed Test</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f4f4f4;
text-align: center;
}
.container {
margin-top: 50px;
}
button {
padding: 15px 30px;
font-size: 16px;
margin: 10px;
cursor: pointer;
}
#clickButton {
display: none; /* Hide the click button until the test starts */
}
</style>
</head>
<body>
<div class="container">
<h1>Click Speed Test</h1>
<p id="instructions">Click the button as fast as you can!</p>
<button id="clickButton" onclick="handleClick()">Click Me!</button>
<p id="score">Score: 0</p>
<p id="timer">Time Left: 10 seconds</p>
<button id="startButton" onclick="startTest()">Start Test</button>
</div>
<script>
let score = 0;
let timeLeft = 10; // Time limit in seconds
let timerId;
function startTest() {
score = 0;
timeLeft = 10; // Reset time
document.getElementById("score").innerText = "Score: " + score;
document.getElementById("timer").innerText = "Time Left: " + timeLeft +
" seconds";
document.getElementById("clickButton").style.display = "inline-
block"; // Show the click button
document.getElementById("startButton").disabled = true; // Disable
start button
if (timeLeft <= 0) {
clearInterval(timerId);
endTest();
}
}
function handleClick() {
score++;
document.getElementById("score").innerText = "Score: " + score;
}
function endTest() {
document.getElementById("clickButton").style.display = "none"; // Hide
the click button
alert("Time's up! Your score is: " + score);
document.getElementById("startButton").disabled = false; // Enable
start button again
}
</script>
</body>
</html>