Syntax error / unsophisticated code / always prints "rock"


#1


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


I have few problems with my code:
1. When I keep the curly braces, like they suggest it in the hints, it tells me there is a syntax error ( SyntaxError: Unexpected token { )
2. When I remove the curly braces, it kinda works, but always prints "rock" as computer's choice
3. Everybody here ask about "choice1" and I don't even know what it is. All the codes quoted here seem to be much different and more developed than mine. The desired outcome was: the user writes whatever and then the program randomly prints "rock" or "paper" or scissors", but in my case it's always rock.


var userChoice = prompt("answer")
var computerChoice = Math.random()
if (computerChoice < 0.33) {
    console.log("paper");
} else if (0.34 < computerChoice < 0.67) {
    console.log("scissors");
} else (0.67 < computerChoice < 1) {
    console.log("rock");
}


#2

You've got a lot mixed-up -- including the logic. Please, kindly go through the instructions again.

I'll give a head start below.

var userChoice = prompt("answer");
var computerChoice = Math.random();
console.log(computerChoice);
if(computerChoice <= 0.33) {
computerChoice = "rock" ;
}

Also, your else shouldn't have a condition/expression attached.


#3

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