<script>
// a simple code to gusse the right number
console.time("gusse time");
let randomnumber = Math.random() * 100;
randomnumber = Number.parseInt(randomnumber);
let gusse = prompt("enter number");
gusse = Number.parseInt(gusse);
let chances = 1;
while (randomnumber != gusse) {
chances++;
console.log(chances);
if (randomnumber == gusse) {
document.write(randomnumber);
break;
}
if (randomnumber > gusse) {
alert("gusse is small");
gusse = prompt("try again");
continue;
}
if (randomnumber < gusse) {
alert("gusse is big");
gusse = prompt("try again");
continue;
}
}
document.write("right answer is ", randomnumber);
document.write("<br>");
document.write("you took ", chances, "chances to get the answer");
console.timeEnd("gusse time");
</script>
top of page
Search
Post: Blog2_Post
bottom of page
تعليقات