Build "Rock, paper, scissors"


#1

what wrong on my code its correct but it does’t show who is the winner

var userChoice = prompt("Do you choose rock, paper or scissors?");
var computerChoice = Math.random();
if (computerChoice < 0.34) {
	computerChoice = "rock";
} else if(computerChoice <= 0.67) {
	computerChoice = "paper";
} else {
	computerChoice = "scissors";
} console.log("Computer: " + computerChoice);

var compare = function (userChoice , computerChoice){
    
    if (userChoice === computerChoice){
    
        return "The result is a tie!";
    
        }
    
        else if (userChoice === "rock"){
    
            if(computerChoice === "scissors"){
    
                return "rock wins";
    
                } else {
    
                    return "paper wins";
                    }
            }
            else if (userChoice === "paper"){
                if (computerChoice === "rock"){
                    return "paper wins";
                    } else {
                        return "scissors wins";
                        }
                } 
                else if (userChoice === "scissors"){
                    if (computerChoice === "paper"){
                        return "scissors wins";
                        } else {
                            "rock wins";
                            }
                    }
    };
    

















#2

you never call the compare function? Functions only execute when called


#3

yes i didn’t call it, i was following what the exercise told me


#4

which exercise, this one:

https://www.codecademy.com/en/courses/javascript-beginner-en-Bthev-mskY8/1/4

step 3 of the instructions tells you to call the function


#5

yes this one , i called functiom compare
https://www.codecademy.com/en/courses/javascript-beginner-en-Bthev-mskY8/1/5?curriculum_id=506324b3a7dffd00020bf661


#6

idk javascript have some bug, sometimes i wrote the code correct and it doesn’t show me it’s correct, and sometimes The opposite is true


#7

There is no bug in RPS Js track

Show me your code, that you add the function call


#8

i solved it !! thank you


#9