<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Random Circles</title> <style> body { margin: 0; overflow: hidden; background-color: #f0f0f0; } .circle { position: absolute; width: 50px; height: 50px; border-radius: 50%; cursor: pointer; } #score { position: fixed; top: 10px; right: 10px; font-size: 50px; } #timer { position: fixed; top: 10px; left: 10px; font-size: 24px; } #startButton, #restartButton { position: fixed; top: 50px; left: 10px; font-size: 20px; padding: 10px 20px; background-color: #007bff; color: WHITE; border: BLACK; cursor: pointer; } #loseMessage { display: none; position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); font-size: 48px; font-weight: bold; text-align: center; color: red; } </style> </head> <body> <div id="timer">Time: <span id="countdown">60</span> seconds</div> <button id="startButton">Start</button> <button id="restartButton" style="display: none;">Restart</button> <div id="score">Score: <span id="points">0</span></div> <div id="loseMessage">GOOD JOB</div> <script> let circles = []; let score = 0; let started = false; let circleCounter = 0; const maxCircles = 100; let countdownValue = 60; // 1 minute document.getElementById('startButton').addEventListener('click', function() { if (!started) { started = true; startTimer(); createCircle(); // Create the first circle } }); document.getElementById('restartButton').addEventListener('click', function() { restartGame(); }); function startTimer() { const countdownElement = document.getElementById('countdown'); const countdownInterval = setInterval(() => { countdownValue--; countdownElement.innerText = countdownValue; if (countdownValue <= 0) { clearInterval(countdownInterval); if (circleCounter < maxCircles) { document.getElementById('loseMessage').style.display = 'block'; document.getElementById('restartButton').style.display = 'block'; } } }, 1000); } function createCircle() { if (circleCounter >= maxCircles) return; // Stop creating circles if the limit is reached const circle = document.createElement('div'); circle.className = 'circle'; const x = Math.random() * (window.innerWidth - 100) + 50; // Adjusted for circle size const y = Math.random() * (window.innerHeight - 100) + 50; // Adjusted for circle size circle.style.left = x + 'px'; circle.style.top = y + 'px'; circle.style.backgroundColor = '#' + Math.floor(Math.random()*16777215).toString(16); // black color circle.onclick = function() { score++; document.getElementById('points').innerText = score; createCircle(); // Create a new circle when clicked this.remove(); // Remove the clicked circle circleCounter++; // Increment circle counter if (circleCounter >= maxCircles) { ("You Win! Your final score is: " + score); // Display "You Win" when all circles are clicked restartGame(); } }; document.body.appendChild(circle); circles.push(circle); } function restartGame() { circles.forEach(circle => circle.remove()); circles = []; score = 0; started = false; circleCounter = 0; countdownValue = 60; document.getElementById('points').innerText = score; document.getElementById('countdown').innerText = countdownValue; document.getElementById('loseMessage').style.display = 'none'; document.getElementById('restartButton').style.display = 'none'; } </script> </body> </html>
Write, Run & Share HTML code online using OneCompiler's HTML online Code editor for free. It's one of the robust, feature-rich online Code editor for HTML language, running on the latest version HTML5. Getting started with the OneCompiler's HTML compiler is simple and pretty fast. The editor shows sample boilerplate code when you choose language as HTML
. You can also specify the stylesheet information in styles.css
tab and scripts information in scripts.js
tab and start coding.
HTML(Hyper Text Markup language) is the standard markup language for Web pages, was created by Berners-Lee in the year 1991. Almost every web page over internet might be using HTML.
<!DOCTYPE html>
<html>
and ends with </html>
<h1>
to <h6>
where <h1>
is the highest important heading and <h6>
is the least important sub-heading.<p>..</p>
tag.<a>
tag.
<a href="https://onecompiler.com/html">HTML online compiler</a>
<img>
tag, where src
attribute consists of image name.<button>..</button>
tag<ul>
for unordered/bullet list and <ol>
for ordered/number list, and the list items are defined in <li>
.<a href="https://onecompiler.com/html">HTML online compiler</a>
CSS(cascading style sheets) describes how HTML elements will look on the web page like color, font-style, font-size, background color etc.
Below is a sample style sheet which displays heading in green and in Candara font with padding space of 25px.
body{
padding: 25px;
}
.title {
color: #228B22;
font-family: Candara;
}
<table>
tag.<tr>
tag<th>
tag<td>
tag<caption>
tag<script>
is the tag used to write scripts in HTML<script src="script.js"></script>