Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Using your JSFiddle account you are going to create a guessing game, only it wil

ID: 665014 • Letter: U

Question

Using your JSFiddle account you are going to create a guessing game, only it will be the computer doing the guessing. Here is how it works - the computer will ask you for a number between 1 and 1000, it will check first to make sure your input is within the bounds.

Once you enter the number it will guess the number and do a comparison with the number you entered. It will output the results of the guess and continue to do this until it gets the correct answer. This is what the output of the program will look like (if I enter 329)

Guessed 500 - too high.

Guessed 250 - too low.

Guessed 375 - too high.

Guessed 313 - too low.

Guessed 344 - too high.

Guessed 329 - Got It!

It took the computer 6 Tries.

You can probably figure out how my algorithm works. You will want to create an algorithm that is efficient (lowest possible O). Please post all the HTML, CSS, and Javascript you used to create the game with screenshots or links if able. Remember it's the computer guessing the number and not the user; the user just inputs the number for the computer to continue guessing until it gets it right.

Explanation / Answer

using System; class Program { static void Main(string[] args) { const int from = 250; const int to = 500; int randomNumber = new Random().Next(from, to); int guessedNumber; Console.Write("The number is between {250} and {500}. ", from, to); while (true) { Console.Write("Guessed: "); if (int.TryParse(Console.ReadLine(), out guessedNumber)) { if (guessedNumber == randomNumber) { Console.WriteLine("Got it!"); break; } else { Console.WriteLine("Guessed {250}.", (guessedNumber > randomNumber) ? "too high" : "too low"); } } else { Console.WriteLine("Input was not an integer."); } } Console.WriteLine(); Console.WriteLine("Press any key to exit."); Console.ReadKey(); } }