Build rock paper scissors lesson 7


#1

Hi guys, newbie here.
I get to the point where I can choose whether I want one of the options and then I get the "Ooops...M in Math.random should be capital". In my code M is capital. Don't know where I am wrong..

var userChoice = prompt ("Do you choose rock, paper or scissors?");
var computerChoice = Math.random();
if (computerChoice < 0.34) {
    computerChoice = "rock";
} else if(computerChoice <= 0.67) {
    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") {
      if(choice2 === "scissors") {
        return "rock wins";
    }
    else {
        return "paper wins";
    }
}
    else if(choice1 === "paper") {
      if(choice2 === "rock") {
        return "paper wins"
    }
    else {
        return "scissors wins";
    }    
}
else if(choice1 === "scissors") {
    if(choice2 === "paper") {
        return "scissors win"
    }
    else {
        return "rock wins"
    }
}
}

Javascript functions lesson 7
#2

The only thing I see off is "scissors win" should be "scissors wins". Fix that and try resubmitting. :slight_smile:


#3

Still get the same result. Let me try rewrite everything step by step and hopefully I will find an error and post it here.
Thanks biff75!


#4

uhm.. which exercise are you at? 3. computerChoice part1?

It is the only exercise in which i can reproduce your error message. The problem is here:

if (computerChoice < 0.34) {
    computerChoice = "rock";
} else if(computerChoice <= 0.67) {
    computerChoice = "paper";
} else {
    computerChoice = "scissors";
} console.log("Computer: " + computerChoice);

in this exercise ComputerChoice should have a random value:

var computerChoice = Math.random();

your if/else if/else clause overwrites it. Having too much code in a exercise can cause trouble.


#5

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