Capital M is wrong error?


#1



3. Computer Choice: Part1.
I've tried to complete the game as I find it easier than doing it step by step. I don't know what is wrong with the Math.random code.


Oops, try again. Did you set var computerChoice = Math.random() ? The capital 'M' in 'Math' is important!


var userChoice = prompt("Do you choose Rock, Paper, Scissors or Rope?");
var computerChoice = Math.random();

if (computerChoice <= 0.24) {
    computerChoice = "Rock";
} else if (computerChoice > 0.24 && computerChoice <= 0.50) {
    computerChoice = "Paper";
} else if (computerChoice > 0.50 && computerChoice <= 0.75) {
    computerChoice = "Scissors";
} else {
    computerChoice = "Rope";
}

console.log("Computer choose: " + computerChoice);

var compare = function(choice1, choice2) {
    if (choice1 === choice2) {
        return userChoice = prompt("The result is a tie!\nPlease make a new choice...");
    }
    
    if (choice1 === "Rock") {
        if (choice2 === "Paper") {
            return "Paper Wins!";
        } else if (choice2 === "Scissors") {
            return "Rock Wins!";
        } else {
            return "Rope Wins!";
        }
    }

    if (choice1 === "Paper") {
        if (choice2 === "Rock") {
            return "Rock Wins!";
        } else if (choice2 === "Scissors") {
            return "Scissors Wins!";
        } else {
            return "Rope Wins!";
        }
    }

    if (choice1 === "Scissors") {
        if (choice2 === "Rock") {
            return "Rock Wins!";
        } else if (choice2 === "Paper") {
            return "Scissors Wins!";
        } else {
            return "Scissors Wins!";
        }
    }

    if (choice1 === "Rope") {
        if (choice2 === "Rock") {
            return "Rope Wins!";
        } else if (choice2 === "Paper") {
            return "Rope Wins!";
        } else {
            return "Scissors Wins!";
        }
    }
};

compare(userChoice,computerChoice);


#2

the additional code in the exercise is the problem, this line:

var computerChoice = Math.random();

means computerChoice now holds a random number, the checking script checks this, but you overwrite it, which causes the error. Maybe add a multi-line comment for the moment? multi-line comment:

/*
all the things which should be commented out 
*/

/* start the comment, */ ends it


#3

Are you saying I shouldn't have the brackets, is that what is making it overwrite?


#4

Now, you overwrite the random number stored in computerChoice here:

if (computerChoice <= 0.24) {
    computerChoice = "Rock";
} else if (computerChoice > 0.24 && computerChoice <= 0.50) {
    computerChoice = "Paper";
} else if (computerChoice > 0.50 && computerChoice <= 0.75) {
    computerChoice = "Scissors";
} else {
    computerChoice = "Rope";
}

#5

Ok thank you, I have fixed the code now.