In this unique piece of code, the code picks a random integer between 1 and 100 and sets it to the numberToGuess. Our code also assigns three other variables, win, guess and numberOfTries. Every time you make a guess, the integer you select is set to the guess value, then it is checked of it is equal to the numberToGuess. If it is not the numberToGuess, then win remains false and two new methods are run. The first method checks if the guess is greater than the numberToGuess. If true, then it will tell you that your guess is too high. Else, if the guess is less than the numberToGuess the code will tell you your guess is too low. Every time a guess is made, one is added to the numberOfTries. When the guess is equal to the randomly assigned numberToGuess, the boolean value win is set to true and the build ends after telling you the numberToGuess and the numberOfTries.
No comments:
Post a Comment