Last active
August 29, 2015 13:57
-
-
Save makyo/9899912 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
alert('Think of a number from 1 to 100...'); | |
var currGuess = 50; | |
do { | |
var response = prompt('I guess ' + currGuess + ' - am I too [h]igh, too [l]ow, or [r]ight on?'); | |
if (response[0].toLowerCase() === 'h') { | |
currGuess--; | |
} else if (response[0].toLowerCase() === 'l') { | |
currGuess++; | |
} else { | |
break; | |
} | |
} while (true); | |
alert('Got it! Your number is ' + currGuess); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
alert('Think of a number from 1 to 100...'); | |
var currGuess = 50, max = 100, min = 0; | |
do { | |
var response = prompt('I guess ' + currGuess + ' - am I too [h]igh, too [l]ow, or [r]ight on?'); | |
if (response[0].toLowerCase() === 'h') { | |
max = currGuess; | |
} else if (response[0].toLowerCase() === 'l') { | |
min = currGuess; | |
} else { | |
break; | |
} | |
currGuess = Math.round(min + (max - min) / 2); | |
} while (true); | |
alert('Got it! Your number is ' + currGuess); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment