Martin Uhomoibhi
Martin Uhomoibhi

Reputation: 11

Parser Error (Javascript Beginner looking for solutions)

I'm new, so forgive my question if its somewhat banal. I received this error while learning Javascript: SyntaxError: Parser error

Here's my code(I'm writing a simple Rock, Paper, Scissors Program):

var userChoice = prompt("Rock, Paper or Scissors?");
computerChoice = "null";

var randomnumber = Math.floor(Math.random()*1);
if (randomnumber <= (1/3)){
        computerChoice = "Rock";
    }
else if ((randomnumber > (1/3)) && (randomnumber <= (2/3))){
        computerChoice = "Paper";
    }
else {
    computerChoice = "Scissors";
}    
}
console.log(computerChoice);

Where did I go wrong?

Upvotes: 0

Views: 47

Answers (2)

roland
roland

Reputation: 7775

You forgot to declare computerChoice as a variable:

var computerChoice = null; //watch out "var"

Upvotes: 0

Ajay2707
Ajay2707

Reputation: 5808

Give function name first with parenthesis , then always use syntax of if else which automatically create parenthesis pair, work in it.....so never you get error.

To find this type of error use firebug addons of firefox.. which tell you exact line no...(if single js you called else it give the appropriate code with line no.)

var userChoice = prompt("Rock, Paper or Scissors?");
computerChoice = "null";

var randomnumber = Math.floor(Math.random()*1);
if (randomnumber <= (1/3))
{
        computerChoice = "Rock";
}
else if ( (randomnumber > (1/3)) && (randomnumber <= (2/3)) )
{
        computerChoice = "Paper";
}
else {
    computerChoice = "Scissors";
}    
//} this is wrong.
console.log(computerChoice);

Upvotes: 1

Related Questions