<!DOCTYPE html> <!-- This is just my basic HTML5-valid template. Make sure you set this up correctly for your personal needs -->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<script language="javascript" type="text/javascript">
window.onload = prep();
function prep(){
count = 0;
generatedNumber = Math.floor(Math.random() * 100 + 1); //Generate number between 1 and 100
if (console){
console.log("generatedNumber: " + generatedNumber);
}
guess();
}
function guess(){
guessedNumber = parseInt(prompt("What number I am thinking of?", "")); //Convert input into a number
if (!guessedNumber){
//Cancel selected
return false;
}
checkNumber();
}
function checkNumber(){
count++;
var diff = Math.abs(guessedNumber - generatedNumber);
if (diff == 0){
alert ("That is correct!");
win();
return false; //Stop the script from running guess() again
} else if (diff <= 3) {
alert("You're red hot!");
} else if (diff < 10) {
alert("You're getting warm.");
} else if (diff < 20) {
alert("You're getting cold.");
} else {
alert("You're ice cold.");
}
guess();
}
function win(){
if (count < 5) {
alert("You win! You did an awesome job! \nIt only...
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.