5/9 function not returning "result is a tie!"


#1

Hi,

I cannot seem to get the code to output "result is a tie" at the end of the code. when i hit submit and save code it says that its right and i can move on but its still not showing

any help would be great:

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

#2

It seems correct... why don't you try refreshing?:smiley:


#3

You are returning that value or string so to see you need to call the compare(arg1,arg2) function and pass it as an argument(token) to console.log() like this

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

#4

you need to call the compare function

insert at the bottom:

compare(computerChoice, userChoice);

Try this


#5

the console.log is not needed as if the 2 choices are the same then it will return the message, but clever thinking


#6

@cloudrunner68456 Check this out on playground
Click here


#7

@rydan it does work but is unnecessary code as if you run the code without the console.log it also works. That is all I am saying.


#8

without console.log only the last value is echoed.


#9

@cloudrunner68456 yeah the code works perfectly but then he wanted to see the result printed to the console thats why I suggested the use of console.log()


#10

i know what the problem is now.

it is because @crooky3005 has removed the comments from the original code.

it does not require you to put in the function call.

P.S @rydan you are right. just calling the function should work but does not,