<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Cookie Clicker with Upgrades and Achievements</title> <style> body { text-align: center; font-family: 'Arial', sans-serif; } #cookie { width: 200px; height: 200px; margin-top: 50px; cursor: pointer; } #score { font-size: 24px; margin-top: 20px; } .upgrade { margin: 10px; padding: 5px 10px; font-size: 16px; cursor: pointer; } .achievement { margin: 10px; font-size: 16px; } </style> </head> <body> <h1>Cookie Clicker with Upgrades and Achievements</h1> <img id="cookie" src="cookie.png" alt="Cookie" onclick="clickCookie()"> <p id="score">Score: <span id="scoreValue">0</span></p> <h2>Upgrades</h2> <p id="clickValue">Click Value: 1</p> <button class="upgrade" onclick="buyUpgrade(10, 2)">Upgrade 1 (Cost: 10 cookies)</button> <button class="upgrade" onclick="buyUpgrade(20, 4)">Upgrade 2 (Cost: 20 cookies)</button> <h2>Auto-Clicker</h2> <p id="autoClickerStatus">Auto-Clicker: Off</p> <button class="upgrade" onclick="buyAutoClicker(50, 1)">Buy Auto-Clicker (Cost: 50 cookies)</button> <button class="upgrade" onclick="buyUpgradeAutoClicker(30, 1)">Upgrade Auto-Clicker (Cost: 30 cookies)</button> <h2>Achievements</h2> <p class="achievement" id="achievement1">Achievement 1: Not yet achieved</p> <p class="achievement" id="achievement2">Achievement 2: Not yet achieved</p> <!-- Add more achievements as needed --> <script> // JavaScript code for the cookie clicker game with upgrades, auto-clicker, and achievements var score = 0; var clickValue = 1; var autoClickerEnabled = false; var autoClickerInterval; var upgradeCount = 0; var cookiesAchievementThreshold = 100; var upgradesAchievementThreshold = 5; var autoClickerAchievementThreshold = 1; function clickCookie() { score += clickValue; updateScore(); // Check and update achievements checkAchievements(); } function updateScore() { document.getElementById("scoreValue").innerText = score; } function updateClickValue() { document.getElementById("clickValue").innerText = "Click Value: " + clickValue; } function updateAchievement(achievementId, message) { document.getElementById(achievementId).innerText = message; } function buyUpgrade(cost, increase) { if (score >= cost) { score -= cost; clickValue += increase; upgradeCount++; updateScore(); updateClickValue(); // Check and update achievements checkAchievements(); } else { alert("Not enough cookies to buy this upgrade!"); } } function buyAutoClicker(cost, initialSpeed) { if (score >= cost && !autoClickerEnabled) { score -= cost; autoClickerEnabled = true; document.getElementById("autoClickerStatus").innerText = "Auto-Clicker: On"; autoClickerInterval = setInterval(autoClick, 1000 / initialSpeed); // Check and update achievements checkAchievements(); } else if (autoClickerEnabled) { alert("Auto-Clicker is already enabled!"); } else { alert("Not enough cookies to buy the Auto-Clicker!"); } } function buyUpgradeAutoClicker(cost, speedIncrease) { if (score >= cost && autoClickerEnabled) { score -= cost; clearInterval(autoClickerInterval); autoClickerInterval = setInterval(autoClick, 1000 / (1 + speedIncrease)); // Check and update achievements checkAchievements(); } else { alert("Either Auto-Clicker is not enabled, or not enough cookies to buy this upgrade!"); } } function autoClick() { score += clickValue; updateScore(); } function checkAchievements() { // Check and update achievements based on thresholds if (score >= cookiesAchievementThreshold) { updateAchievement("achievement1", "Achievement 1: Unlocked!"); } if (upgradeCount >= upgradesAchievementThreshold) { updateAchievement("achievement2", "Achievement 2: Unlocked!"); } if (autoClickerEnabled && score >= autoClickerAchievementThreshold) { // Add more achievements as needed for other thresholds } } </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>