Build "Rock, Paper, Scissors" code dosent work


#1

I'm trying to build this game "Rock, Paper, Scissors" and when I hit the submit button I always get a syntax error.
I don't know where the problem is. I tried looking at my code piece by piece and I cant spot what is wrong with it.
but when I copy and paste someone else's code that's look similar to mine, it works

here is my code that always get a syntax error, if you could look at it and tell me where I am wrong?

var userChoice = prompt("Do you choose rock, papaer or scissors?");
    var computerChoice = Math.random()
    //console.log(computerChoice)
    if(computerChoice <=0.33){
        computerChoice == "rock"
    };
        else if(computerChoice  <= 0.66){
            computerChoice == "paper"
        };
            else{
                computerChoice == "scissors"
            };

#2

 if(computerChoice <=0.33){
        computerChoice == "rock"
    };  // remove ;
        else if(computerChoice  <= 0.66){
             computerChoice == "paper"
         };   //remove ;
            else{
               computerChoice == "scissors"
           };    // remove ;

now

computerChoice == "rock" // you need to assign

i would do

computerChoice = "rock"

same for the rest


#3

Hi first remove alla The ; You put after each closing } Then These Lines

computerChoice == "rock"
computerChoice == "paper"
computerChoice == "scissors"

Change The == with = Because You want to set computerChoice to (rock, papera or scissors) And not to compare it to Them


#4

Thank you !
I've done what you said and it finally works!


#5

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