This tutorial got frozen


#1

The game is working fine, but every time I run instead of passing to next step the alert is displayed:
"Oops, try again.
Did you set var computerChoice = Math.random() ? The capital 'M' in 'Math' is important!"

What is wrong? There is this exact sentence in code...

var userChoice = prompt("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 win";
        }
    }
    else if (choice1 === "scissors") { 
        if (choice2 === "rock") {
            return "rock wins";
        }
        else {
            return "scissors win";
        }
    } 
};

console.log(compare(userChoice, computerChoice));

#2

How can you already have all the code? Either way, i recommend to comment it out, it is throwing the checking script off, just log the console the computerChoice after the random choice of the computer, comment out the rest


#3

I have some programing background, so I wrote the game after initial hints (very helpful). The game was fine, but I realized that creators of the tutorial expect fulfilling some precise steps/formulas. I realized that modifying my code would be futile so i pasted solution from the forum :wink:
Anyway thanks for the answer, I will try it.
My initial code was

function userChoice(){
var choice = prompt("choose: scissors paper or rock?");
return choice;
}

function computerChoice(){
var choice = 'rock';
var dice = Math.random();

if (dice < 0.33){
    choice = 'scissors';
}    
else
    if (dice < 0.66){
        choice = 'paper';
    }    
    
return choice;

}

//
//
//

function compare (){
var result;
var choice1 = userChoice();
var choice2 = computerChoice();

alert ("you: "+ choice1 + " vs comp: " + choice2);

if (choice1 === choice2)
   result = "tie";
else{
   var effect = choice1+choice2;
   if (effect == "rockscissors" || effect == "scissorspaper" || effect == "paperrock")
      result = "you win";
   else
      result = "computer wins"; 
}        
return result;

}
var iJak = compare();
alert (iJak);