Functions, step 6. Need help


#1

Hi,

I'm having trouble with exercise in javascript introduction, "Functions, return II".

https://www.codecademy.com/courses/learn-javascript/lessons/functions/exercises/return-ii

The problem is in getTax function. Error message is: "Did you pass in orderCount to the getSubtotal function inside the getTax function's block?
Did you multiply the subtotal by 0.06 (or 6%)?"

I didn't get further for now, so exercise isn't complete. I was wondering why can't I multiply getSubTotal by 0.06 and just get tax?

Thanks in advance

var orderCount = 0;

function takeOrder(topping, crustType) {
  console.log('Order: ' + crustType + ' crust topped with ' + topping);
  orderCount = orderCount + 1;
}

function getSubTotal(itemCount) {
  return itemCount * 7.5;
}

function getTax() {
  return getSubTotal(orderCount) * 0.06;
}

function getTotal() {
  return getSubTotal(orderCount) + getTax();
}


takeOrder('bacon', 'thin');
takeOrder('pepperoni', 'regular');
takeOrder('pesto', 'thin');

console.log(getSubTotal(orderCount));
console.log(getTotal());

#2

Your code looks fine, try to refresh browser or reset the code (of course, copy code before reset).


#3

Hi, thanks for fast answer.

Could you tell me please why couldn't line be

Why do I have to use (orderCount)? I couldn't find answer.
I tried without it but it wasn't correct.

Thanks

P.S. I passed the exercise, it seems like it needed a refresh or it was just bugged at the moment.


#4

Because you need the parameter "itemCount" to run the function "getSubTotal." The "getSubTotal" function returns "itemCount" multiplied by 7.5:

function getSubTotal(itemCount) {
  return itemCount*7.5;
}

When you run the getTax function, you're asking the getSubTotal function to use the orderCount variable. The getTax function will run the getSubTotal function with that parameter (multiplying the orderCount variable by 7.5), then multiply the product by 0.06:

function getTax(){
  return getSubTotal(orderCount)*0.06;
}

If you try to instead just multiply "getSubTotal" by 0.06, it won't work, because the function doesn't have a value to work with and won't be able to return a number.


#5

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