Return


#1

I don’t understand 2 things:

  1. what value does itemCount gets?
  2. what’s wrong with my code?

https://www.codecademy.com/courses/learn-javascript-functions/lessons/functions/exercises/return?action=resume_content_item&course_redirect=introduction-to-javascript


#2

Did you call the getSubTotal function with passing in the orderCount as a parameter?

As an argument, to be factual, but yes, your function call has no argument, orderCount.


#3

But where should i type it? inside the getSubTotal(orderCount) ??


#4

Yes, just as you have written it above.


#5

But i get this output: Your subtotal is NaN

That means it doesn’t have any value right?


#6

Please post your code, not a screenshot.


#7

You have a parameter for the function getSubTotal(). But when you call it, you don’t give it a parameter. Look at this:

var nameCaller = function(name) {
     console.log("Hello " + name);
}

nameCaller() <-- you need an argument, like "Sam" or "Tom"

Try changing that with your code.


#8

In the call expression, it is not a parameter, but an argument. The parameter is the receiving variable.

Examples should not go against normal practice. It is never a good idea to name a function and its variable the same thing.


#9

@mtf Fixed that. But am I right about that? Or is there something else.


#10

just the terminology.

function foo(parameter) {

}

foo(argument);

#11

I see… Oh no! I was wrong. He is asking what value item count gets. Sorry!


#12

We’re still waiting to see the member’s code. If there is no response then this will end up as an unresolved topic and will get removed eventually.


#13

@mtf I know whats wrong with the code now.

  1. He didn’t obey the instructions
  2. You can’t add any strings like “Your subtotal is”, you have to only call the function in the console.log statement.

#16

I fixed it already, but still i didn’t entirely understand the function of return

let orderCount = 0;

const takeOrder = (crustType, topping) => {
orderCount +=1;
console.log('Order : ’ + crustType + ’ pizza topped with ’ + topping);
}

const getSubTotal = (itemCount) => {
return itemCount * 7.5;
}

takeOrder(‘thin’, ‘pepperoni’);
takeOrder(‘thick’, ‘sausage’);
takeOrder(‘normal’, ‘ham’);

console.log(getSubTotal(orderCount));

Also, i don’t have clear yet where does itemCount gets its value


itemCount's value
#17

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.