Expected [Function


#1

I’m working on the functions coding exercise. The instructions are as follows: ‘Inside the getTax() function, call your getSubTotal() function and pass it the argument orderCount to get the subtotal, and then multiply the returned value by 6% (0.06). Make sure to return the result of this operation.’.

I’m getting the error expected [function

Here is my code

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

const getSubTotal = orderCount => {
  return orderCount * 7.5;
};

const getTax = orderCount => {
  return getSubTotal(orderCount) * .06;
};


takeOrder('thin crust','pepperoni');
takeOrder('garlic crust', 'supreme');
takeOrder('hand tossed', 'anchovies');
console.log(getSubTotal(orderCount));

#2

One error that may not be related is the order of the arguments not matching up to the order of the parameters. The arguments determine the order, meaning your output is switched.


#3

Yea that’s unrelated, I’m aware of that.


#4

Which lesson is this? Please post a link. Thanks.


#5

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


#6

My code has four functions, not three.

takeOrder, getSubTotal, getTax and getTotal.

Each function takes a different input primarily for demonstration.

getTotal = () {};

No argument, but the global variable orderCount is polled.

getTax = (orderCount) {};

Because the variable represents a discrete value, a number, it is copied to the local variable of the same name. This variable will shadow the global, meaning it cannot be polled from inside the function. The local variable is the value that is polled inside the function. Any change to that value will not be reflected in the global.

(In fact a global can be shadowed and still accessible via the window object. )

getSubTotal = (itemCount) {};

In the above we are creating an arbitrary name for the local variable. Like above, the value of orderCount will be copied to the local variable. That means the global is still accessible from inside the function. Any change to itemCount will not be reflected in the global.


#7

The checks for the correct coding is very touchy.

One issue I found was that if you use .06 (As was used above) instead of 0.06 it will not clear the 2nd step.

Here is the code that I’m using: Which is also correct according to the solution given, but won’t clear the 3rd step…

let orderCount = 0;

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

takeOrder('mushroom', 'thin crust');
takeOrder('spinach', 'whole wheat');
takeOrder('pepperoni', 'brooklyn style');

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

const getTax = () => {
  return getSubTotal(orderCount) * 0.06;
};

const getTotal = () => {
  return getSubTotal(orderCount) + getTax();
};

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

#8

On the last line of the program, call the getTotal() function inside of a console.log() statement to view the result.

My code does not have a line for getSubTotal(), just getTotal().

In my code, these lines appear at the bottom, after all the functions and before the last line.


#9

It’s not that the code is wrong, but the triggers for the steps to be completed aren’t working depending on how it’s written.
I literally asked for the solution, then repeated the lesson and the solution as expressed by the lesson wouldn’t trigger the step to be complete. :confused:


#10

Once you ask for code, the SCT is shut down. Reset the lesson and try again.


#11

Right, that’s exactly what I’m saying. I reset the lesson and the code it gave didn’t work for some steps… even when I tried to remove portions of the code to complete the individual steps.


#12

Best one can advise is the usual litany… Different browser, clear cookies, etc., none of which come with any guarantees. Please be sure to Report a Bug on the page in question. Thanks.


#13

Yup, looks like that was the issue. Reloaded browser and now all is right with the world. Thank you!


#14

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