Computer Choice Part 2


#1


https://www.codecademy.com/courses/javascript-beginner-en-Bthev-mskY8/0/4?curriculum_id=506324b3a7dffd00020bf661#


Please help! I don't know what the error(s) is/are in my code. Thanks!


var userChoice = prompt("Do you choose rock, paper or scissors?")
var computerChoice = Math.random();
console.log(computerChoice) 
if (computerChoice > 0 && computerChoice <= 0.33) {
    return"rock";
}
else if (computerChoice >= 0.34 && computerChoice <= 0.66) {
    return"paper";
}  
else (computerChoice >= 0.67 && computerChoice <= 1) {
    return"scissors";
}
};


#2

Hi there.

Your else block does not need a condition to test because the else block runs when everything else above it is false.

Also there's an extra curly brace that is not necessary.

.
}
};

One of these must go!


#3

Hi, I ended up using the code below. Thanks a lot for your help!

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


#4

Hi there.
Can I ask you why the ; is not suposed to be between the if , else if , else?


#5

Thank you! Couldnt figure it out but I think I got it now


#6

To webwhiz66661, I found this on the Codecademy Blog from 2013: https://www.codecademy.com/blog/78


#7

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