Skip to content

Instantly share code, notes, and snippets.

@rodvan
Created February 9, 2015 21:10
Show Gist options
  • Save rodvan/a8fb2c9cbcd0c0ec1547 to your computer and use it in GitHub Desktop.
Save rodvan/a8fb2c9cbcd0c0ec1547 to your computer and use it in GitHub Desktop.
JS Bin // source http://jsbin.com/wugifekibu
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body>
<script id="jsbin-javascript">
//Random number and then the machine will guess it.
var upper = 10000;
var randomNumber = getRandomNumber(upper);
var guess;
var attempts = 0;
function getRandomNumber(upper) {
return Math.floor( Math.random() * upper) + 1;
}
while ( guess !== randomNumber ) {
guess = getRandomNumber(upper);
attempts += 1;
}
document.write("<p> the random number was: " + randomNumber + "<p>");
document.write("<p>It took the computer " + attempts + " attempts to get it right.</p>");
</script>
<script id="jsbin-source-javascript" type="text/javascript">
//Random number and then the machine will guess it.
var upper = 10000;
var randomNumber = getRandomNumber(upper);
var guess;
var attempts = 0;
function getRandomNumber(upper) {
return Math.floor( Math.random() * upper) + 1;
}
while ( guess !== randomNumber ) {
guess = getRandomNumber(upper);
attempts += 1;
}
document.write("<p> the random number was: " + randomNumber + "<p>");
document.write("<p>It took the computer " + attempts + " attempts to get it right.</p>");</script></body>
</html>
//Random number and then the machine will guess it.
var upper = 10000;
var randomNumber = getRandomNumber(upper);
var guess;
var attempts = 0;
function getRandomNumber(upper) {
return Math.floor( Math.random() * upper) + 1;
}
while ( guess !== randomNumber ) {
guess = getRandomNumber(upper);
attempts += 1;
}
document.write("<p> the random number was: " + randomNumber + "<p>");
document.write("<p>It took the computer " + attempts + " attempts to get it right.</p>");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment