"What if choice1 is rock?" What is wrong with my code?


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

var computerChoice = Math.random(1,0);

if (computerChoice 0 < 0.33) {
	computerChoice = "rock";
}
else if(computerChoice 0.3 <= 0.66) {
	computerChoice = "paper";
} 
else {
	computerChoice = "scissors";
} 
console.log("Computer: " + computerChoice);
/*--------------------------------------------*/
var compare = function(choice1, choice2) {
    if(choice1 === choice2) { {
        return "The result is a tie!";
    }
    
    else if(choice1 === "rock") {
    return"?";
    }
    
    if(choice2 === "scissors") {
        return "rock wins";
    }
    else {
        return "paper wins";
    }
    
}

#2

I do not know what it says when it is wrong, but I have found a problem. There may be more, for "Build Rock, Paper, Scissors" requires a really long amount of code.

On your "if" statement (the one right below your function), you have double brackets.


#3
if (computerChoice 0 < 0.33) {
	computerChoice = "rock";
}
else if(computerChoice 0.3 <= 0.66) {
	computerChoice = "paper";
}

The conditions doens't work. Here I wrote a post about double conditions:
https://www.codecademy.com/forum_questions/51fc4178f10c60f4eb001233#answer-529f101f7c82ca3ce100308d

Also the else if should not return anything but inhabit the if and the else that follows it. Maybe have a look at the whole FAQ thread or at least at the hint of 6/9 to see how one of these cases looks like.

The idea is that the else if deal with the userChoice (choice1) whereas the nested if/else determine the result based on the computerChoice (choice2).


#4

Thanks for the help!