Functions Flashcards

1
Q

Create a working function that would be a helpful tool for waiters that logs what a customer wants to order?

A
function takeOrder(topping, crustType) {
console.log('Order type: ' + crustType + 'pizza topped with ' + topping);
}
takeOrder(pineapple and ham, thick crust);
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

When functions return their value, we can use them together and inside one another. How can you expand onto a function that takes the orders for customers and gets the subtotal, the tax, and the grand total?

A
Var orderCount = 0;
Function takeOrder(topping, crustType) {
	console.log(‘Order: ’ + crustType + ‘ pizza topped with’ + topping);
	orderCount = orderCount + 1;
}
function getSubTotal (itemCount) {
	return orderCount * 7.50;
}


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


}


Function getTotal () {
	return getSubTotal(orderCount + getTax());
}
takeOrder(‘pineapple and ham’, ’thick crust’);
console.log(‘Your subtotal is:’, getSubTotal(orderCount))
console.log(‘Your total is:’ getTotal)


How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Whats the difference between where a global variable can be accessed and where a functional variable can be accessed?

A

A global variable can be accessed anywhere and a function variable can only be accessed within it’s function

How well did you know this?
1
Not at all
2
3
4
5
Perfectly