Question: INSTRUCTIONS: * Make a guessing game where the computer guesses what the human user's * number is between 0 and 100 (inclusive). Do NOT use

INSTRUCTIONS:

* Make a guessing game where the computer guesses what the human user's

* number is between 0 and 100 (inclusive). Do NOT use Arrays and do NOT use a linear search algorithm!

* Use if-else and confirm("some question") inside the while-loop.

* The human is expected to click the cancel button to indicate No (confirm function returns false)

* or the OK button to indicate Yes (confirm function returns true).

* Do NOT change the line "guess = Math.round((min + max) / 2);"

* because the computer is supposed to guess efficiently by

* asking the human if their number is higher, lower, or equal to

* the computer's current guess.

* You can use "return" inside the while-loop to get the computer

* to leave the guesser function.

*/

Java Script's code:

var guesser = function () {

'use strict';

var min = 0;

var max = 100;

var guess;

alert("Think of a number betwwen 0 and 100");

while (min <= max) {

guess = Math.round((min + max) / 2);

// Add your code below here ONLY!

if (confirm("Question 1: Please click 'OK' to answer Yes, or click 'Cancel' to answer No.")) {

alert("Your answer to Question 1 was 'Yes'.");

} else if (confirm("Your answer to Question 1 was 'No'. Question 2: Please click 'OK' to answer Yes, or click 'Cancel' to answer No.")) {

alert("Your answer to Question 2 was 'Yes'.");

} else {

alert("Your answer to Question 2 was 'No'.");

}

// Move or remove the next line. It is only here to prevent an infinite loop.

return;

// Add your code above here ONLY!

}

alert("I could not guess your number.");

};

window.onload = guesser;

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!