Rock paper scissors


#1


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


I know I haven't gone far but I when I run my small piece of code it prints out 0.8926652756439979 and false. It is should to print out the number but why is it giving me "false" as a response also?

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


#2

@scriptsurfer71380 you should not have this:

it should have console.log().

Hope this helps.

Steven


#3

It doesn't print false, just the number. If more is printed then something else is doing that printing.

Also, you should clean up that formatting, newline after { and de-indent at the end of a group of statements. Be consistent:

var userChoice = "rock";
var computerChoice = Math.random();
console.log(computerChoice);

if (computerChoice < .34) {
    computerChoice === "rock";
}
else if (computerChoice <= .66) {
    computerChoice === "paper";
}
else {
    computerChoice === "scissors";
}

Another thing to at least notice is that 1/3 and 2/3 would be better values to use. Still not exact because floats are not exact, but a whole lot closer.


#4

Thanks. That solved it. I was confused by the instructions


#5

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