How to write in another js program


#1



The code works perfect but my question is when I try to write the code in another js program it dosen't do anything exept asking to choose from rock, paper or scissors.
What I mean is it dosen't return for example :
Computer: scissors
"rock wins"


Replace this line with your code.


#2

You do call the function and have a console unit? Can i see your code? Where are you trying to run it?

try jsbin, it has a console unit


#3

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

I use "Free Java script editor" but i also used some other online program
PS: In codecademy it works when i run it


#4

console.log logs things into the console, and codecademy als logs the last thing returned. This is not standard behavior. Free javascript editor is just a editor, where do you see the output? If it in the browser, you really need to open the console, and you might want to wrap the function call in a console.log statemetn