This is a color guessing game. However when I try to run it from TextWrangler nothing happens. But when I use a javascript editor online the game works perfectly. Is there something wrong with my code or is there a problem with TextWrangler???
<!doctype html>
<html>
<head>
<title>Guess the Color Assignment 2 Part 1</title>
</head>
<body onload=("do_game ()")>
<script type="javascript/text">
var target_index;
var guess_input_text= "none";
var guess_input;
var finished = false;
var guess = 1;
var colors=["blue","yellow","red","green","brown","black"];
colors= colors.sort();
function do_game () {
var random_number = (Math.random() * (colors.length-0)) + 0;
var random_number_integer = Math.floor(random_number);
target_index= random_number_integer;
var target = String(colors[random_number_integer]);
alert("" + target);
while (!finished) {
guess_input_text = prompt("I am thinking of one of these colors: \n\n" +
colors.join(",") + "\n\n What color am I thinking of?");
guess_input = colors.indexOf(guess_input_text);
guess += 1;
finished = check_guess();
}
}
function check_guess () {
if(guess_input == -1) {
alert("That is not is not option. Try again. \n\n");
return false;
}
if(guess_input > target_index) {
alert("That color is alphabetically higher than the correct answer.");
return false;
}
if(guess_input < target_index) {
alert("That color is alphabetically lower than the correct answer.");
return false;
}
if(guess_input == target_index) {
alert("You are correct!!!!! You guessed the right color!" + "\n\n It took you " + guess + " tries to finish the game.");
myBody=document.getElementsByTagName("body")[0];
myBody.style.background= target;
return true
}
}
</script>
</body>
</html>