0
window.onload=function(){
        contents = new Array();
        painted = new Array();
        keys = 0;
        for(var i = 0; i < 4; i++){
            contents[i] = '';
            painted[i] = false;
        }
        contents[0] = 1;

    }

    function clicked(canvasNumber){
        if(contents[canvasNumber-1] == 1;){
            alert("you won!");
        }
    }

I am trying to get a pop up saying, "you won!" when canvas 1 is clicked, but the contents of my contents array are not matching up to trigger that alert. What am I doing wrong?

3
  • I also want to add that all variables have already been declared. Commented Oct 14, 2013 at 14:29
  • 2
    How are you calling clicked ? Commented Oct 14, 2013 at 14:32
  • 1
    In addition to the semi-colon answer below, have you defined contents outside the functions to make it a global? Commented Oct 14, 2013 at 14:36

1 Answer 1

1
if(contents[canvasNumber-1] == 1;){

should be

if(contents[canvasNumber-1] == 1){

with no semicolon in the if statement

Also your indexes are most likely not aligned.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.