The code has no syntax error warning... but don't show the result


#1

The code has no syntax error warning... but don't show the result.... some one can help me?


It wont work!
#2

You should call the function compare like that

compare(userChoice, computerChoice )

At end after your code.


#3

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("User: " + userChoice);
console.log("Computer: " + computerChoice);
var compare = function(userChoice, computerChoice) {
if (userChoice === computerChoice) {
return "The result is a tie!";
}
else if (userChoice === "rock") {
if (computerChoice === "scissors") {
return "rock wins";
}
else {
return "paper wins";
}
}
else if (userChoice === "paper") {
if (computerChoice === "rock") {
return "paper wins";
}
else {
return "scissors wins";
}
}
};


#4

Try to add that at the end of your code

compare(userChoice, computerChoice )

#5

it work's.... many thanks wiz! just to learn... why do you put that line at the end? how's work?


#6

Its the call fucntion it works like that after you create a function you should call it to have a output.
LIke that

var sum = function(num1, num2) {
     return num1 + num2
}

Here you call it with the number you like

sum(2,3)

#output
    5

#7

super many thanks!!!!!!! :beers: