You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
<!DOCTYPE html>
|
|
|
|
|
<!-- saved from url=(0065)file:///C:/Users/Pusha/Downloads/Telegram%20Desktop/solution.html -->
|
|
|
|
|
<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
|
|
|
|
|
|
|
|
|
<title></title>
|
|
|
|
|
</head>
|
|
|
|
|
<body>
|
|
|
|
|
<script>
|
|
|
|
|
|
|
|
|
|
// Написать игру "Отгадай число"
|
|
|
|
|
// Компьютер загадывает число от 1 до 10 и у игрока есть 3 попытки, чтобы его отгадать
|
|
|
|
|
// в случае неверной попытки выводится подсказка "больше" или "меньше"
|
|
|
|
|
|
|
|
|
|
// function randomNumber(min, max){
|
|
|
|
|
// if (max === undefined) {
|
|
|
|
|
// max = min;
|
|
|
|
|
// min = 0;
|
|
|
|
|
// }
|
|
|
|
|
// return Math.round(Math.random() * (max - min)) + min;
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// var guessCount = 3;
|
|
|
|
|
// var isRight = false;
|
|
|
|
|
|
|
|
|
|
// function game() {
|
|
|
|
|
// var rand = randomNumber(1, 10);
|
|
|
|
|
// console.log(rand);
|
|
|
|
|
// for (var n = 0; n < guessCount; n++) {
|
|
|
|
|
// userVariant = +prompt("Отгадайте число от 1 до 10");
|
|
|
|
|
// if (rand === userVariant) {
|
|
|
|
|
// isRight = true;
|
|
|
|
|
// break;
|
|
|
|
|
// } else {
|
|
|
|
|
// alert( (rand > userVariant) ? "больше" : "меньше" );
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// if (isRight) {
|
|
|
|
|
// alert("Ура!!");
|
|
|
|
|
// } else {
|
|
|
|
|
// alert("было загадано число " + rand);
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// game();
|
|
|
|
|
// </script>
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
// Мой вариант
|
|
|
|
|
|
|
|
|
|
function f1(x, r){
|
|
|
|
|
if (x === r) {
|
|
|
|
|
alert('Win!');
|
|
|
|
|
return true;
|
|
|
|
|
} else if (x > r) {
|
|
|
|
|
alert('You number is bigger');
|
|
|
|
|
return false;
|
|
|
|
|
} else if (x < r) {
|
|
|
|
|
alert('You number is smaller');
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
var userVariant, rand;
|
|
|
|
|
rand = Math.floor((Math.random() * 10) + 1);
|
|
|
|
|
|
|
|
|
|
var guessCount = 3;
|
|
|
|
|
for (var n = 0; n < guessCount; n++) {
|
|
|
|
|
userVariant = +prompt('Enter number 1 - 10');
|
|
|
|
|
result = f1(userVariant, rand);
|
|
|
|
|
if (result) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (result === false) {
|
|
|
|
|
alert('It was number: ' + rand);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
</body>
|
|
|
|
|
</html>
|