Code does not open JavaScript alert and prompt windows

<PLEASE USE THE FOLLOWING TEMPLATE TO HELP YOU CREATE A GREAT POST!>

<Below this line, add a link to the EXACT exercise that you are stuck at.>

<In what way does your code behave incorrectly? Include ALL error messages.>
Why does this html file not open the alert and prompt window? What is wrong with this code? Please help!

```

<!doctype html>

Colors
<do not remove the three backticks above>

you call function before define, you should insert this in the <head>...</head>

<script type="text/javascript">
var guess;
var required = false;
function do_game(){
    var colors = ['aqua', 'black', 'blue', 'brown', 'cyan', 'gold', 'gray', 'green', 'magenta', 'orange', 'pink', 'red', 'yellow', 'white'];
    var num = math.floor(math.random() * 14)
    var color = colors[num]
    alert("The target color is " + color)
    while !required{
        guess = prompt("I am thinking of one of these colors"/n/n + colors /n/n + "What color am I thinking of?");
        if guess == color {required = true};
    }
}
</script>

Still not working bro :confused:

What do you want to do???
@abdulahhamzic

ommm now i check your code, you should change some things,
semicolon( ’ ; ’ ) after all state line . for example: var color = colors[num];

another thing is use ‘(’ and ‘)’ . for example while(!required){...}

and another thing is Capitalize sensitive. there is no math object, that are Math

and special characters is wrong /n/n, this is \n that should be covered by " ".
now your code should be this:

<!doctype html>
<html>
<head>
<title>Colors</title>

<script type="text/javascript">
var guess;
var required = false;
function do_game(){
    var colors = ['aqua', 'black', 'blue', 'brown', 'cyan', 'gold', 'gray', 'green', 'magenta', 'orange', 'pink', 'red', 'yellow', 'white'];
    var num = Math.floor(Math.random() * 14);
    var color = colors[num];
    alert("The target color is " + color);
    while(!required){
        guess = prompt("I am thinking of one of these colors\n\n" + colors + "\n\n What color am I thinking of?");
        if (guess == color) {required = true};
    }
}
</script>

</head>
<body onload="do_game()">
</body>
</html>

test it,
i dont remember that use fuctions that are define after is work or not(in js) but is better to use this.

good job

1 Like

Thanks mate, you did the job for me, appreciate it!