function searchNumber botNum botNum 50 return Math floor botNum 50 25

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
function searchNumber (botNum) { // botNum = 50.
return Math.floor(botNum / 2); // 50 / 2 = 25.
}
const minNum = 1;
const maxNum = 50;
let numb = Math.floor(Math.random() * 51); // numb = 17.
let botNum = maxNum; // botNum = 50.
let isNumberFound = false;
let count = 0;
while (!isNumberFound) {
if (searchNumber(botNum) == numb) { // 18 != 17.
alert ('Yahoo it is ' + botNum);
isNumberFound = true;
} else if (searchNumber(botNum) > numb) {// 18 > 17.
alert ('Search lower');
botNum = searchNumber(botNum); // 18 / 2 = 9.
} else { // 12 < 17.
alert ('Search higher');
botNum = searchNumber(botNum + (botNum / 2)); // 12 + (12 / 2) = 12 + 6 = 18.
}
count++;
}