This forum is now read-only. Please use our new forums! Go to forums

0 points
Submitted by neno1478
over 8 years

Rock paper scissors 3/9 whats wrong?

var userChoice=prompt(“Do you choose rock, paper or scissors?”); var computerChoice = Math.random(); console.log(computerChoice) if (computerChoice===0-0.33===”rock”) { console.log(“computer:” computerChoice) } else if (computerChoice===0.34-0.66===”paper”) { console.log(“computer:” computerChoice) } else { (computerChoice===0.67-1===”scissors”) console.log(“computer:”computerChoice) };

Answer 55c9ba829113cbae27000199

4 votes

Permalink

Exercise 3/9 correct code should like this:

var userChoice = prompt("Do you choose rock, paper or scissors?");
var computerChoice = Math.random();
console.log(computerChoice);

Exercise 4/9 correct code should look like this:

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.67) {    
    computerChoice = "paper";
} else {                          
    computerChoice = "scissors";
}
points
Submitted by Yehosua Selah
over 8 years

3 comments

AS over 8 years

console.log(computerChoice) needs removing from where you have it because at that point computerChoice is just equal to a floating point number. The variable is not yet allocated a string term.

The correct code should have the console.log(computerChoice); statement after the if/else statement because at this point the variable computerChoice has been given the string (IE: what the computer has chosen).

Syed Kazmi over 8 years

Thanks alot

Dumitru Axentii over 8 years

thanks. this helped!