Partial code being printed out into console.log and not sure why


#1

I’m passing all the criteria required to move on to the next exercise but the output of the console is giving me parts of my code and not the desired output and I can’t work out why. Can someone point me in the right direction please? I don’t want to move on until I understand why and where I’ve made a mistake.

I’m also scratching my head as to why orderCount isn’t outputting orderCount + 1 for each iteration of takeOrder

Any help would be greatly appreciated

This is the code

let orderCount = 0;

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

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

takeOrder('mushrooms', 'thin');
takeOrder('pineapple', 'deep pan');
takeOrder('cheese', 'regular');
takeOrder('ham', 'crispy');

console.log('The cost is ' + getSubTotal + ' and the  number of items is ' + orderCount);

And this is the output on the console

Order: thin crust topped with mushrooms
Order: deep pan crust topped with pineapple
Order: regular crust topped with cheese
Order: crispy crust topped with ham
The cost is (itemCount) => 
{
  const SubTotal = (itemCount) * 7.5;  
  return itemCount;  
} and the  number of items is 0

#2

Ok so I fixed the orderCount issue by changing “orderCount = orderCount++” to simply “orderCount++”


#3

Ok all fixed!

I wasn’t calling the parameter for getSubTotal so it was treating everything after getSubTotal as a string and printing it out.

getSubTotal (itemCount)

#4

We do not need to reassign the compound increment.

orderCount++;

is all we need to write. It is a statement expression, already.

Rather than return itemCount, return the subTotal.

We need to invoke the function.

getSubTotal(orderCount)

#5

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