6.Don't Repeat Yourself (D.R.Y)


var orangeCost= function (price) {

Cant think of anything. Help please with this code. If you can otvetet in Russian, do it yourself.

I dont know where is the problem


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

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


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


**"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 ) );


After you have read the Function talk
Please read


couple mistakes:

  • in your console.log output, you don't need quotation marks.
  • last line (orangeCost(5)) has bad syntax... you need to add something.


Hi! I stuck in same part.
Why do I get two answers?

What is wrong?
// I apologize for my poor english


You will have to use the return statement instead of the console.log() method
you only have to return price*5
no other text....


@vucurs I used the exact same code as yours, with same results. Based on the instructions so far this is logical for us, but the answer of @leonhard.wettengmx.n is the one they want:

PS return is explained in the next exercise :joy:


as you are using the return statement the normal call would have to be
console.log( orangeCost(5) );


Tx. I couldn't make this up from the instructions, but it seems logical from what I want to do: print to screen.


Keep this in mind while doing the course

It is the Javascript interpreter which is running in this course-environment,
it display's the last non-displayed action...

You will also encounter this, when you are doing a return-statement
as last action...
You could counter this by using a
console.log( " " ); as last statement....

In some sections of this course, the course-checker Display's data
this you could then identify by placing two EXTRA code-line's:
console.log( "== My End ==" );
console.log( "== All that is displayed now, is the course-checker ==" );


@leonhard.wettengmx.n Now you made me curious, so I went back to try. Indeed there's no output when I finish with another console.log() statement. So console.log(organgeCost(5)) is the only proper syntax.


I think you could also replace your 2 console.log() Methods
with 1

console.log("== My End ==');


Here is my code

var orangeCost = function(price) {
var orangeCost= price * 5;



It's good idea if you add the missing semicolons as well to your return statement, end of the function and also the end of the console.logs.


Hi @amarillia I deliberately don't. It's a course and I want to find out what I think of those semi-colons. Whether I like my code with or without. Besides this I'm also curious - after my PHP course :slight_smile: - when things work without semi-colons.


I would read some article's found with google search
== discussions / opinions ==
javascript when to use semicolon site:stackoverflow.com
== the Book ==
semicolon site:developer.mozilla.org


It doesn't want you to return any verbiage just the calculated number.


Here is what I put for and it came back correct.

var orangeCost = function (number)
var val = number * 5;


you can use this


We haven't covered 'Return' yet so wouldn't this simply be the answer they were asking for?