Hello, function with if/else


#1

Someone knows the response for that ?

SyntaxError: Unexpected token

Oops, try again. There was a problem with your syntax

var quarter = function(number);// Define quarter here.
return 16/4;
quarter(4);

if (quarter() % 3 === 0 ) {
console.log("The statement is true");
} else {
console.log("The statement is false");
}


#2

@codewhiz71790,

the FUNCTION talk

var myFunc = function( param1, param2) {
       //Begin of  anonymous FUNCTION-BODY
       //VARIABLE -myFunc- has an -anonymous function- assigned
       //this -anonymous function- has 2 PARAMETERS param1 and param2
       //param1 and param2 PARAMETERS are used 
       //as -local- VARIABLES throughout the FUNCTION-BODY

      console.log( param1 + " and " + param2 ) ;

      //End of anonymous FUNCTION-BODY
};

If you want to call/execute the anonymous function
you will have to add a pair of parentheses to the variable myFunc
like
myFunc();
As the anonymous function was defined
as having 2 parameters
you have to provide 2 arguments
in our case 2 string VALUES "Alena" and "Lauren"
like
myFunc("Alena","Lauren");

some quotes from the outer-world:

**argument is the value/variable/reference being passed in,
parameter is the receiving variable used within the function/block**

OR

**"parameters" are called "formal parameters",
while "arguments" are called "actual parameters".**


#3

@codewhiz71790,

function with 1 parameter using return-statement

var myFunction = function( param1 ) {
       //Begin of FUNCTION-BODY
       //myFunction =function= has 1 PARAMETER param1
       //this param1 PARAMETER is used as a -local- VARIABLE
       //throughout the FUNCTION-BODY

      return param1;

      //End of FUNCTION-BODY
      };

you have defined a myFunction function
which takes 1 parameter param1
this param1 parameter is used
as a variable throughout the FUNCTION-BODY.

If you want to call/execute this myFunction function
and this myFunction function was defined
as having 1 parameter param1
you will have to provide 1 argument
in our case a "number VALUE" 4
myFunction( 4 );

some quotes from the outer-world:

**argument is the value/variable/reference being passed in,
parameter is the receiving variable used within the function/block**

OR

**"parameters" are called "formal parameters",
while "arguments" are called "actual parameters".**

============================================

As you are using the return-statement in your myFunction function
you will only get a return-value no-display.
You can however capture this return-value in a variable
and then use the console.log()-method to do a display.

var theResult = myFunction( 4 );
console.log( theResult );

OR directly

console.log( myFunction( 4 ) );

#4

Your code look a bit off try to format the code like this.
1) copy and paste your code
2) highligt/select your whole code
3) then look for this </> and press it.
or
simply press ctrl + shift + c and past the code inside the highlighted area.


#5

@s09abcd,

before the selected code, there should be a blank line


#6

Yes leave one line as a space before following the step.


#7

Hi, Mr Wetteng

I admire your knowledgement about Functions, your logical-math besides the method, but it's very stuck for me. So Could you please give me the answer ?? because I effectively, did it WRONG.

// Define quarter here.
myFunction = function (12) {
return (0);
quarter(4);
console.log(myFunction(12 % 4));
};

if (quarter(12) % 3 === 0 ) {
console.log("The statement is true");
} else {
console.log("The statement is false");
}

SyntaxError: Unexpected number

Oops, try again. There was a problem with your syntax


#8

This is not being reached after a return(0) i think!


#9

Why do you make this so complicated? Wasn't the quarter function pre-set for the exercise?
The idea is that you just use a function to calculate the quarter of a number so:

var quarter = function(number){
    return number/4;
}

#10

thank you, but 4 is impossible to be.. therefore 4 % 3 = 1, not 0


#11

I guess his point was that anything in a function that comes after return is ignored as return quits the function. But as said that is not the only problem in your function.


#12

Ok, man.. Thanks, Anyway it'll help me.