<button id="playPause">
Play Game
</button><br>
Score: <span id="score"></span><br>
HighScore: <span id="highScore"></span><br>
Status: <span id="gameStatus"></span><br>
Timer: <span id="gameTimer">00:00</span><br>
JavaScript
var consoleLog = true;
var paused = false;
var initReq = true;
var highScore = 0;
var score = generateRandomIntegerInRange(0, 30); // pseudo score
const gameButton = document.getElementById("playPause");
const gameStatus = document.getElementById("gameStatus");
const timeDisplay = document.getElementById("gameTimer");
const hscore = document.getElementById("highScore");
function init() {
second = 1000; // 1 sec = 1000 ms
maxTime = 20; // Base Time
extTime = 10; // Extended Time
s = 0; //second count
xScore = 20; // score must be gt or equal for extended play
extPlay = false;
}
function waitforme(millisec) {
return new Promise(resolve => {
setTimeout(() => { resolve('') }, millisec);
})
}
async function gameTime() {
// Play Game
for (s = 0; s < maxTime + 1; ++s) {
if (paused) return;
await waitforme(second);
countDown = maxTime - s; /* reverse count */
status = displayTime(countDown);
updateConsole(status);
// Warning: Time is almost up!
if (countDown == 5) {
status = updateGameStatus("Time Is Almost Up!");
updateConsole(status);
}
// Extended Play
if (s == maxTime-1){
if (score >= xScore && extPlay == false) {
maxTime = maxTime+extTime;
extPlay = true;
status = updateGameStatus("Extended Play");
updateConsole(status);
}
}
}
gameOver();
}
function displayTime(seconds) {
gameTimer.innerHTML = pad(seconds);
return seconds;
}
function gameOver() {
status = updateGameStatus("Game Over");
updateConsole(status);
updateGameButton("Play Again");
// loadData(); // may have changed since initial pageload
if (score > highScore) highScore = score;
updateHighScore(highScore);
// updateGameCounter();
// storeData();
// reset for new game
initReq = true;
init();
score = generateRandomIntegerInRange(0, 30); // remove
}
// Generate a random number within range including the min and max
function generateRandomIntegerInRange(min,...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.