5/9 confusing


#1

i removed the comment tags and added my part of the code.

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(userChoice === computerChoice){
        return "The result is a tie";
    }
};
compare(userChoice, computerChoice);

The output is a tie, however the editor says ...Oops, try again. Your compare function does not return 'The result is a tie!' when there is a tie....what am I doing wrong here...???


#2

Forgot a ! at the end of the sentence.


#3

I would change

if(userChoice === computerChoice)

with

if(choice1 === choice2)

and

compare(userChoice, computerChoice);

with

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

#4

thanks a lot guys...I edited the code with both suggestions from haxor789 and hacker92...and it works


#5

Awesome! Did you understood why? Just asking as it is important with understand how it works!


#6

How it works?????????????????????????


#7

Could you be a bit more specific?


#8
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 tie!";
}
};
console.log(compare(userChoice,computerChoice));

Getting error Your compare function does not return 'The result is a tie!' when there is a tie.


#9

Ok took me some time as the code seems to be ok. The problem is that it needs to be is a tie not is tie.


#10

mine still doesn't work. it looks like this:

/*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!";
    }
};
console.log (compare(userChoice, computerChoice));

#11

ok I'm sorry. It was just because I needed to write "The" instead of "the" :smiley: thank you :smiley:


#12

From what I have learnt so far, ALWAYS COPY/PASTE TEXT FROM THE INSTRUCTIONS! DO NOT IMPROVISE!


#13

unfortunately yes. At least for variable names and sentences that are explicitly mentioned there.


#14

I also forgot to write 'a'. This is not done....


#15

Please read
http://www.codecademy.com/forum_questions/559dcb4be39efe550f00006b
and concentrate on
th build of the compare function
the execution of the compare function


#16

Yeah I did understand...thank you very much...