Rock, Paper, Scissors

Why doesn’t my code run how i want it to?

var userChoice = prompt("Are you ready to play rock, paper, scissors?(answer in lowercase)")
if (userChoice === "yes") {
    prompt("Do you choose rock, paper, or scissors")
} else if (userChoice === "no") {
    console.log("You are boring. Run the code again and say yes.")
} else { 
    console.log("That is not a valid answer. Run the code again and say yes")
}

var computerChoice = Math.random();
if (computerChoice <0.34){
    computerChoice = "rock";
}else if(computerChoice <=0.67){
    computerChoice = "paper";
}
else{
    computerChoice = "scissors";
}

var compare = function(userChoice,computerChoice){
    if (userChoice ===computerChoice) {
    console.log("The result is a tie!") ;   
    }

if (userChoice==="rock") {
    if(computerChoice==="scissors") {
        console.log("You Win!");
    }
    else {
        console.log("You loose!");
    }
}

if (userChoice==="scissors" ) {
    if (computerChoice==="paper") {
        console.log("You win!") ;
    }
    else {
        console.log("You loose!");
    }
}

if (userChoice==="paper") {
    if(computerChoice==="rock") {
        console.log("You win!");
    }else{
        console.log("You loose!");
    }

};

compare(userChoice,computerChoice);

}

functions only execute when called

you do have a compare function call, but its within the compare function.

1 Like