Exercise 5. Return


#1

Hi guys,

I don’t understand why I’m getting 0 as the “orderCount” output when I increase the number every time the function “takeOrder” runs.

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

My code is here:


var orderCount = 0;
var totalPrice = 0;

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

function getSubTotal (itemCount) {
	return itemCount * 7.5;
}

takeOrder("bacon", "thin crust");
takeOrder("pineapple", "thick crust");
takeOrder("cheese", "ultra massive crust");

console.log(getSubTotal(orderCount));

Thanks for your feedback!

Cheers, Martin


#2

Use orderCount++ rather than orderCount = orderCount++

The increment operator (++) automatically saves the new value in the variable.


#3

lol @mb.martin.benes re:ulta massive crust


#4

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