SOS - Functions 6/7 code


#1

Hello,

I am not sure if this is correct as it just gives me something odd. Please can anyone help me with this?
Thanks

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

ANSWERS
Order:thinpizza topped withbacon
Order:thinpizza topped withcheese
Order:regularpizza topped withtomatoes
22.5
22.5
[Function: getTotal]

CODE
var orderCount = 0

function takeOrder(topping, crustType){
console.log('Order:' + crustType + 'pizza topped with' + topping);
orderCount= orderCount+1
}
function getSubTotal(itemCount){
return itemCount*7.5;
}

takeOrder ('bacon','thin');
takeOrder ('cheese','thin');
takeOrder ( 'tomatoes','regular');
console.log(getSubTotal(orderCount));
function getTax() {
return getSubTotal(orderCount)*0.06;
}
function getTotal() {
return getSubTotal(orderCount)+
getTax ();
}
console.log (getSubTotal(orderCount));
console.log(getTotal);


#2

Hi @vanesawilson04,

Order:thinpizza topped withbacon
Order:thinpizza topped withcheese
Order:regularpizza topped withtomatoes

You printed this because you have left out a space " " in your string. Here:

function takeOrder(topping, crustType){
console.log('Order: ' + crustType + ' pizza topped with ' + topping); //<== add space after "order:(space)", before pizza "(space)pizza" and after "topped with(space)"
orderCount= orderCount+1; //<== add a semicolon here
}

22.5
22.5

You printed twice of the same price, nothing really wrong here, just repetitive because you have a repeated code of:

console.log(getSubTotal(orderCount));  //<== Delete this one OR
function getTax() {
return getSubTotal(orderCount)*0.06;
}
function getTotal() {
return getSubTotal(orderCount)+
getTax ();
} 
console.log (getSubTotal(orderCount)); //<== OR Delete this one, just delete one of them
console.log(getTotal);

Lastly,

[Function: getTotal]

You printed that because you miss out the brackets for calling a function. It should be getTotal()

console.log (getSubTotal(orderCount));
console.log(getTotal()); //<== Add brackets to call function

I think that's it. Cheers :slight_smile:


#3

Hi codexthon,

You are absolutely right. I'll modify it now.

Thank you very very much.


#4

You're very much welcomed :slight_smile:


#5

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