Functions: Exercise 5


#1


Hi Everyone,

Please help me out with the JavaScript: Functions: Exercise 5, link for the same is as below:

https://www.codecademy.com/courses/learn-javascript/lessons/functions/exercises/return?action=lesson_resume&link_content_target=interstitial_lesson

This is the code I have written:

var takeOrder;
var orderCount = 0;
function takeOrder(crustType, topping)
{
  orderCount++;
  console.log('Order :'+crustType+' pizza topped with '+topping);
}
function getSubTotal(itemCount)
{
  return itemCount*7.5;
}
console.log(getSubTotal(orderCount));
takeOrder('regular', 'bacon');
takeOrder('thin crust', 'extra cheese');
takeOrder('thin crust', 'olives');

The Result, when I run the Program is:
0
Order :regular pizza topped with bacon
Order :thin crust pizza topped with extra cheese
Order :thin crust pizza topped with olives

I am particularly stuck with the result of the program, with the getSubTotal function I am always getting the value 0, is this incorrect or have I written the code correctly?

Please Advice. 
Thanks in advance.


#2

Try changing the call order like

takeOrder('regular', 'bacon');
takeOrder('thin crust', 'extra cheese');
takeOrder('thin crust', 'olives');
console.log(getSubTotal(orderCount));

#3

Additional advice:
var takeOrder is no longer needed and since you have a function with the same name takeOrder is that function.


#4

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