Please help, it doesn't return " the result is a tie"


#1

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 resulf is a tie";}
};

#2

Run it several times, the computerChoice is random every time. You also have to call your function on the last line compare(userChoice, computerChoice)


#3

the problem is probably a missing ! at the end of the sentence.


#4

first:you forget a curly brace at the end of "var compare =function(choice1, choice2)";
second:at the end of the code ,you should call the compare function


#5

The end of compare is actually fine but there is an opening { missing at the start :smile:
Calling the function is optional at this point but doing so might help as you can see if your code is working as expected. Just run the test cases:

compare("rock","rock");
compare("paper","paper");
...

for this case it might not be that intersting but as this grows you might find it useful.


#6

put exclamation mark at the end of tie . and it will work.... as they have string setup exactly like this in previous parts

here is correct code :smile:

*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!";
}
};

hope it helps


#7

hahahhaa!! Thank it was


#8

Thanks everyone who helped :smile: