Лови
<!DOCTYPE html>
<html>
<head>
<title>1</title>
</head>
<body onload="do_game()">
<script>
var target;
var guess_input_text;
var guess_input;
var finished = false;
var guesses = 0;
var colors=["Tomato", "Violet", "Snow","Salmon", "Purple", "Navy","OliveDrab", "Lime", "LightGray","HotPink", "Gold", "Gainsboro"];
var alphacolors = colors.sort();
function do_game(){
var random_number = Math.random() *(alphacolors.length-1);
var random_number_integer = Math.floor(random_number);
target = random_number_integer + 1;
while (!finished) {
guess_input = prompt("I am thinking of a color \n\n" +
"What is the color, huh? ");
guesses += 1;
finished = check_guess();
}
}
function check_guess() {
if (!alphacolors.indexOf(guess_input)) {
alert("Sorry, I don't recognize your color \n\n" +
"Please try again");
return false;
}
if (guess_input > target) {
alert("Sorry! Your guess is not correct. \n\n" + "But I can help you: \n" + "your color is alphabetically higher than mine \n\n" + "Please try again");
return false;
}
if (guess_input < target) {
alert("Sorry! Your guess is not correct. \n\n"+"But I can help you: \n"+"your color is alphabetically lower than mine \n\n"
+"Please try again");
return false;
}
alert("You got it! The color was " + target +
".\n\n It took you " + guesses +
" guesses to get the right color");
myBody = document.getElementsByTagName("body")[0];
myBody.style.background=target;
return true;
}
</script>
</body>
</html>
Перенос строки не
n\ а
\n :O