Solution for More on Control Flow in JS (9.2)


#1

Finally solved, but do not know how, except by looking at some of other peoples mistakes, trial and error. That is an acceptable reason I should feel good for, right?? Thought this might help people and if someone can explain why this works I would be thankful.


#2

@dissalv,
To fully test the isEven function
you would have used

isEven("a string");
isEven(8);
isEven(3);

With the isNaN() method
you are testing if the given argument for number is-NOT-a-Number
= https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/isNaN

With number %2 === 0 you are using the remainder / modulo functionality
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
8%2 You read 8 nodulo two is zero, as 8 divided by 2 will have NO rest-value

=https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators
( look for the remainder operator )

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

++++ 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 ) );