Why is my function "undefined"?


When I called the total function in the pizza exercise, I don’t know why but I am keep getting “undefined” as a result. What is the problem of my code?

let orderCount = 0
const takeOrder = (topping,crustType) => { orderCount +=1
  return `Order: ${crustType} pizza with ${topping}.`;

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

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

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

console.log(takeOrder('mashroom','thick crust'));



  getSubTotal(orderCount) *0.06;

has to be on a single line, otherwise the default value is returned

if you want to put it on multiply lines, use parentheses:

return (
  getSubTotal(orderCount) *0.06;


Omg ! It worked.!
It did not work because I was returning noting.
From now on I will pay more attention to the lines.
Thank you so much!


that can’t be, value has to be returned, so very like undefined (the default returned value)

you’re welcome :slight_smile:


Hi @webmaster82737,

This situation happened because of how JavaScript operates, one mechanism which referred as Automatic Semicolon Insertion:

Specifically for return case

If the value is omitted, undefined is returned instead.

For more reading about ASI (It does not only affect return but others as well):

Just sharing the relevant documentations here. Happy learning! :slight_smile:


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