Syntax error on paper rock scissors game


#1

"There was a problem with your syntax" (browser) missing ) after formal parameters


var userChoice = prompt("Do you choose rock, paper or scissors?");

var computerChoice = function(Math.random())
{

console.log(computerChoice);


if (computerChoice <= 0.33)
{
    computerChoice = "rock";
}
else if (computerChoice > 0.33 && computerChoice <= 0.66)
{
     computerChoice ="paper";
}
else(computerChoice >= 0.67 && computerChoice <= 1)
{
     computerChoice ="scissors";
}}


#2

you dont need function keyword for Math.random() .you could simply do like

var computerChoice = Math.random()

The random() method returns a random number from 0 (inclusive) up to but not including 1 (exclusive)

and else doesn't allow to have a condition.you dont need that condition too.


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.