8/9 how do you call function?


#1

:weary: I need instructions on how to call the function. Everything else works fine.


#2

Hi @shineon3,

There are two ways that I know of in which you can make a function:

var _____ = function (parameters){}

function _____(parameters){}

:smiley:


#3

Those are good ways for creating a function but for calling a function you would simply do:

functionName(parameter,parameter);

remember that the parameters that you use when you call the function are the things that you actually want the computer to compare and not the "names" that you used as place holders when making the function


#4

I called my function using
compare(computerChoice,userChoice); and it still will not accept.


#5

did you try it as:

compare(userChoice,computerChoice);

if so then you'll need to post all of your code so we can try to find where the problem is


#6

I understand that this is how to solve a function and for me it works fine. But on the previous exercises, I was forced to create a separate variable and call my function from inside of that. Why the difference?


#7

I tried this finally. It worked! It really worked! Thank you so much for your help.


#9

At least here:

else if(choice1==="rock"){
        if (choice2==="scissors"){
            return"rock wins";}
        else{
            return"paper wins";}
}
// here should be a } for the rock else if.
else if(choice1==="paper"){

you're missing a } before the next else if to close the previous one.


#10

I tried it with an extra } but it still doesn't work..
SyntaxError: Unexpected token else


#11

and i could pass the previous exercise without this extra } so the problem should be somewhere at the end


#12

i copy pasted my code and now it works, strange


#13

Ok your formatting was a bit strange sry. The mistakes I've found were that you missed ending a string somewhere, something like "rock instead of"rock" and that there was an additional } at the end of your code.