Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Larry Ellison Database Genius Of Oracle

Authors: Craig Peters

1st Edition

0766019748, 978-0766019744

More Books

Students also viewed these Databases questions