In this game, the application randomly determines a sample size of numbers. Within the sample, a number is assigned the lucky number.
Your job is to find the lucky number programmatically using as few guesses as possible.
Write a function that consistently finds the lucky number with the least number of guesses.
<div data-value="32" class="number n32">32</div>
Each number is wrapped in a div
that contains the data attribute value
which stores the numeric value of the number. Remember, "32"
is different from 32
.
Each number has two classes when the application initializes:
number
n[X]
The number
class can be used to identify all of the available numbers on the page.
The second class, n[X]
is unique to each number and can be used to identify a specific number on the page. The naming of the unique class follows a simple pattern: the number prefixed with the letter "n". For example, number 32’s unique class will be n32
.
HINT: You’ll need to make use of both of these classes when writing your algorithm to find the lucky number.
Use the guess()
function to make a guess:
guess(number);
guess()
accepts one argument which is the name of the unique class for a given number. For example, if you want to guess 32, write guess('.n32');
.
Each guess will return one of three results:
higher
The lucky number is higher than your guesslower
The lucky number is lower than your guesswin
You guessed the lucky number