What's wrong with my code?


#1


var userChoice=prompt("Do you choose rock,paper,or scissor");
var computerChoice=Math.random();
console.log(computerChoice);
if(computerChoice<0.33){
    computerChoice="rock";
    }
else if(computerChoice<=0.66) {
    computerChoice="paper";
    } 
else
{
    computerChoice="scissors"
    }
var game=function(choice1,choice2){
    if(choice1===choice2){
        return "TIE";
        }
     else if(choice1==="rock"){
         if(choice2==="paper"){
             return "paper win";
             }
            else{
                return "rock win";
                } 
         }
         else if(choice1==="paper"){
             if(choice2==="scissors"){
                 return "scissors win";
                 }
                 else{
                    return "paper win"
                     }
             }
            else{
             if(choice2==="rock"){
                return "rock win"
                 } 
            else{
                return "scissors win";
                }     
                } 
    };   
    game(rock,paper);


#2

your function call (at the very end):

game(rock,paper);

you should pass userChoice and computerChoice as arguments, not rock and paper (undefined variable)

also, the function should be called compare


#3

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