Functions, step 6. Need help



I'm having trouble with exercise in javascript introduction, "Functions, 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');



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


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.


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


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.


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