itemCount, what is it?!?


Hi guys,

need some basics pls, I get the logic behind the functions and the excercise below, however first off I am interested in the following: is there like a list of arguements stored someplace on the web, basically giving me an idea when to use what?

2nd question is related to the itemCount arguement, I cant seem to draw a line how and where it connects to the rest of the code. w3school sample is

var a = x
var b = y
var c = a+b

and it seems fine, however looking at this code, I cant figure out how is itemCount related to the function, as I did not declare it anywhere.

Please help, I kinda have the feeling this is the missing bit to help me understand the background logic of it all.

var orderCount = 0;

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

function getSubTotal(itemCount) {
  return itemCount * 7.5;

function getTax() {
  return getSubTotal(orderCount) * 0.06;

function getTotal() {
  return getSubTotal(orderCount) + getTax();

takeOrder('bacon', 'thin');
takeOrder('pepperoni', 'regular');
takeOrder('pesto', 'thin');



Uhm, sorry lol, found the answer I was looking for like 10 mins after the post.

Basically changed itemCount = orderCount, however one is global, other is local :slight_smile:

just changed the code to replicate the var, changed values and still works like a charm. Get it now.

@admin: feel free to lock topic, will pay more attention nxt time before early bird post :slight_smile:


Actually it´s really helpful to me. Didn´t know about gobal (orderCount) and local (itemCount)

On the other hand, I´m not sure why not change the global var? like

console.log("Sub Total: " + orderCount *7.5) ?


Can you show your solution so I can understand what you mean about changing the other parts of the code around?


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