Choice1 is rock


#1

//Thank you got that to work finally. Now having issue with the next step. After considerable work this this still showing an error message ('unexpected end of input'). Appreciate any help!

var compare = function(choice1, choice2) {
if(choice1 === choice2) {
return("The result is a tie!");
}
else (choice1 === "paper"); {
if(choice2 === "rock") {
return("paper wins");
} else {
return("scissors wins");
}


What if choice 1 is rock: I can't seem to find the syntax error: end of input
#2

else {
return "paper wins";
}
// missing } to close else if
// missing } to close function

#3

//Thank you got that to work finally. Now having issue with the next step. After considerable work this this still showing an error message ('unexpected end of input'). Appreciate any help!

var compare = function(choice1, choice2) {
if(choice1 === choice2) {
return("The result is a tie!");
}
else (choice1 === "paper"); {
if(choice2 === "rock") {
return("paper wins");
} else {
return("scissors wins");
}


#4

This error message is telling us the function body is not closed.


#5

my answer already covers this problem?


#6

Tweaked a few things but still no luck with the code below. After extensive research I can't see how I'm not closing the function properly or how I'm not closing the else if properly.

Any way you can show me this explicitly?

var compare = function(choice1, choice2) {
if(choice1 === choice2) {
return("The result is a tie!");
}
else (choice1 === "paper");
if(choice2 === "rock") {
return("paper wins");
} else {
return("scissors wins");
}
};


#7

var compare = function(choice1, choice2) {
if(choice1 === choice2) {
return("The result is a tie!");
}
else (choice1 === "paper");
if(choice2 === "rock") {
return("paper wins");
} else {
return("scissors wins");
}
}; // this one closes else if, no need for a semi-colon
// still a } missing to close the function

#8

The glaring omission... if.


#9

You've been very helpful and I've done all the exercises up till now and even googled about how to properly close a function. Still not understanding the concepts if you wouldn't mind explaining what closing the function means in this example and where the } goes. Thank you.


#10

Sorry I'm quite new to this and am really dedicated to learning and not just mooching answers. But could you explain where this IF you mention goes? I've sincerely spent a lot of time on this and will take advice from any corners.


#11

Function with parameters and code body:

var compare =  function (choice1, choice2) {
    // if statement code
};

If statement code

    if ( ... ) {

    }
    else if ( ... ) {
        if ( ... ) {

        } else {

        }
    }

Fill in the missing bits and insert the whole thing into the function body.


#12

use else if instead of else


#13

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.