8/13 there was a problem with your syntax...?


#1

Hello,

I've the following code:

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

but somewhere something went wrong and I'm stuck. What should be changed with this code?


#2

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

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

They are asking you to define a quarter function
which takes 1 parameter number.
This number parameter is used as a variable throughout the function-body.
They want you to use the return-statement
to return number/4;

Thus if you would call the quarter function with an argument 12
quarter(12);
you would get a return-number-Value of 3

Now to the % remainder-operator.
Javascript has the so-called modulo / remainder-operator 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
16%8 You read it as sixteen modulo eight is zero, as sixteen divided by 8 has NO rest-value.
quarter(12)%4 You would read three modulo 4 is 3, as three divided by 4 leaves you with a rest-value of 3

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

== discussions / opinions ==
javascript remainder operator site:stackoverflow.com
= http://stackoverflow.com/questions/4467539/javascript-modulo-not-behaving
javascript return statement site:stackoverflow.com
= http://stackoverflow.com/questions/3717420/is-there-a-benefit-to-using-a-return-statement-that-returns-nothing
= http://stackoverflow.com/questions/22134753/return-statement-in-javascript

= https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Comparison_Operators
= https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Expressions_and_Operators

== guidance ==
= www.crockford.com
= http://javascript.crockford.com/survey.html
= http://javascript.crockford.com/code.html


#5

You are NO help so plz stop with all these sites and stuff

PLEASE :rage:


#6

You're not the person asking the question are you? Neither are you contributing any help, are you?
I think @leon's posts are pretty useful and whether this helps or not is something @doapam has to decide as he/she was asking the question. If it is not what you're searching for, then maybe go ahead and phrase your own question.


#7

well my bad if I hurt any ones feelings but when i use these sites I don't understand them so thank you for saying something and I won't do it again :sleepy: :innocent:


#8

That's a pretty lame code you wrote there...sorry but yeah think about it this way, you have not defined "quarter" yet in your if statement so you gotta put a function above your if/else block to define the "quarter" function before actually using it. The if/else only checks for condition AFTER it has received the result that is returned from the quarter function after you pass the value 12 in this case. So that "return number/4" should go into your quarter function, not your if/else block.

The function is as easy as this:

var quarter=function(number){

return number/4 ;
};

Yeah just remember you can't use function you have declared yet and pass value to it, in this case, quarter...


#9

@ajaxsurfer53217,
Reading your last sentence
Yeah just remember you can't use function you have declared yet and pass value to it, in this case, quarter...

Rephrase:

you can't use function that you have not declared yet and pass an argument to it

Comment:

This is not Always true...
have a read through
== discussions / opinions at stackoverflow.com ==
= http://stackoverflow.com/questions/336859/var-functionname-function-vs-function-functionname?rq=1