Https://www.codecademy.com/courses/learn-javascript/lessons/functions/exercises/return-ii?action=resume_content_item


#1

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

the code displayed here is as follows:

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(itemCount){
return getSubTotal(orderCount) * 0.06;
}

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

takeOrder(‘bacon’, ‘thin’);
takeOrder(‘pepperoni’, ‘regular’);
takeOrder(‘pesto’, ‘thin’);

console.log(getTotal());

Why do we need to make another itemCount? I am a bit confused, because it is not declared anywhere in the code, it just appears in the bracket all of a sudden. How does the system know what it is and how to intepret it?

Thanks a lot!


#2

A function doesn’t provide its own input, it acts on the input when it is invoked

function(x) { return x + 1 }

If x was already defined as 5 this function would be nearly useless because it would always return 6


#3

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