The game is only working within Codecademy


#1


I want to create another options to the game, so I copied the final code to a JavaScript editor, but everytime I run it, I get an error on line 10


The error reads "Incompatible types"

I also trying to run just:
var computerChoice = Math.random();
console.log(computerChoice)
but I get the same error, with or without semicolons on line 10

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 === "rock") {
            return "rock wins"
        }
        else {
            return "scissors wins"
        }
    }
}
console.log( compare(userChoice,computerChoice) )


#2

@tbritoamorim,

Try by replacing the console.log()
like

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);

#3

@leonhard.wettengmx.n I did you said, still not working


#4

@tbritoamorim,
In the codecademy-Environment the console.log() is re-routed to the Preview-screen.......
Normally you would only see it in the console of your Debugger.

You could try and replace all of your console.log() statement_ in alert() statements.

or

nice to know

You could test in labs.codecademy.com
choose Javascript
You will get a split-screen
In the left-hand-side you paste-in your code
click on the Run button.
The right-hand-side is the console

references

www.crockford.com --> for most respected guide-line in Javascript
like coding convention
www.crockford.com
http://javascript.crockford.com/code.html <== Javascript code-convention
http://javascript.crockford.com/survey.html


#5

It worked just fine on Codecademy Labs. It's gonna do for me now. Thank you very much, @leonhard.wettengmx.n


#6

What kind of javaScript editor do you use? Often enough people confuse javaScript with Java.