8 Functions, return and if / else


#1



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

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


Replace this line with your code.


#2

@p.a.walters,
You were presented
with the code

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

After you have defined your quarter() Method
which uses 1 parameter number
you are asked to use the quarter() Method
using 1 argument
with a number Value, such that the
condition quarter(--) %3 === 0 results in a true.


#3

@p.a.walters,

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".**

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

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

@p.a.walters,

Javascript has the so-called Remainder-operator %
is actually a modulo-operator
and if used it will return the rest-value.

9%3 You read it as nine modulo three is zero, as 9 divided by 3 has NO rest-value.
22%6 You read 22 modulo six is 4, as 22 divided by 6 will leave you with rest-value 4
10%5 You read 10 nodulo five is zero, as 10 divided by 5 will have NO rest-value

google search
== the Book ==
javascript remainder operator site:developer.mozilla.org
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators

== discussions / opinions ==
javascript remainder operator site:stackoverflow.com
http://stackoverflow.com/questions/4467539/javascript-modulo-not-behaving


#5

stuck in the same spot, sorry leonhard, nothing you are saying its helping at all.


#6

I was stuck on the same problem. I googled it and found this old codecademy forum post helped a lot, I hope it helps you too: https://www.codecademy.com/forum_questions/548927e476b8fe44ff001353


#7

thanks again Leon I've been gone a good while I am back and with a JavaScript and d html cookbook
for extra guidance along these treacherous waters of learning how to code.


#8

You should take a look at your semi-colon placement, you have to many semi-colons in parts of your code. Also your semi-colon needs to be placed after the 4 with curly brackets afterwards like this. Helpfully this helps out some. I know the struggle can be real with coding but keep going and it will all fall in place...

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

console.log("The statement is true");
};
else {
console.log("The statement is false");
};