This is hard


You are a creature of habit. Every week you buy 5 oranges. But orange prices keep changing!
01. You want to declare a function that calculates the cost of buying 5 oranges.
02. You then want to calculate the cost of the 5 all together.
03. Write a function that does this called orangeCost().
04. It should take a parameter that is the cost of an orange, and multiply it by 5.
05. It should log the result of the multiplication to the console.
06. Call the function where oranges each cost 5 dollars.

Do not get these instructions!

The code I have:

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


Hey @codekses! your syntax is wrong. This is how you do it ima show you!

So to create a function just do it the javascript way! Will give you additonal comments!! :smile:

// making a function named price
var price = function(orange){
// making the variable orangeCost that calculates the cost of orange! 1 orange is 5$!
var orangeCost = orange * 5;
// then you log it!
// Last but not Least, you call the function!

If you still dont understand or have any problems! Reply saying so!


It is still saying that it is a problem with my syntax though @amanuel2


Sorry!!! When i called the function i accidently called orangeCost(5)!!! That shouldnt be it change the last line of the calling to


Again im really sorry for this mistake @codekses!! Sorry


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


is that it? It says I need a "{" somewhere



oh the problem is that on your code you didnt need that semicolon at your function! just a minor problem @codekses!

Fix this:

to this:

var price = function(orange)


Hey @codekses,


You put a semi colon between the function and the first corresponding bracket



Okay, so the problem is that the semi colon signals the code that it's the end.

It also can disconnect. Like, a for loop!(You'll get to that sooner)

So, what the semi colon does here:

Is that it makes the function get disconnected with its first bracket. WHICH EQUALS a syntax problem, for then there's no use of the function, the function can't do anything, AND there are leftover pieces of these:

Which cannot function. Makes sense? Comprende? :smiley:

Sorry I had a little fun with the dramatic music there. :grin:


Jeezez Christ, sorry for bothering you so, but now it says I didn't define orangeCost


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



Huh? This image says otherwise? :smile:


As @amanuel2 has shown, you have to refresh there. :smile:

The code now works fine.


But that is the "What is your name" excersise, I'm on the "D.R.Y" excersise



Oh sorry i didnt know that! Yea it gives you that error. The function is supposed to be named orangeCost. So this will do!

var orangeCost = function(price){
    console.log("The cost of orange is" + (price*5) + "$");


If you have trouble understanding anything please reply saying so!


@amanuel2 Also accidentally copy+pasted the code onto the level What is your name? in Getting Started with Programming.

@codekses Sorry, didn't see that.

Also, you don't really have to do as @amanuel2 shows, just console.log price*5. :smiley:


Yeah, lol! Just doing extra work ! Yea like @ragezapper said you dont need to include that part!


i have memorised this process but i am dont fully understand why you have to log or print the "orangeCost" with console.log. Can someone please explain this to me?Thanks