Functions > Return || (6/7)


#1

Functions > Return || (6/7)

The course has marked the code below as correct.
When I run it I get the following:
Order: thin crust topped with bacon
Order: thick crust topped with tomato
Order: pan crust topped with chicken
22.5
NaN

Shouldn’t there be some numbers where Nan is written? Or have I done something wrong?

Thank you

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

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

takeOrder(‘bacon’, ‘thin’);
takeOrder(‘tomato’, ‘thick’);
takeOrder(‘chicken’, ‘pan’);
//Calls the take order function

console.log(getSubTotal(orderCount));
//Outputs the cost of the order

console.log(getTotal());
//Outputs the total cost including tax

<do not remove the three backticks above>

#2

Hi @roseking, have a look at the comment in the code:

function getTax(orderCount) {   //<=== should getTax take in parameter?
return getSubTotal(orderCount) * 0.06;
}

function getTotal() {
return getSubTotal(orderCount) + getTax(); //<=== should getTax be called with an argument?
}

Decide and stick to just one of the option. Example: if you pass a parameter when writing a function, you should call the function with an argument.

But for you to pass the exercise, the instruction didn’t mention writing any parameter for function getTax(). Change that and your code will work.


Note: If you have any more question next time, it’s better to post a link to your exercise, so anyone can have a look which exercise you’re facing issues, then format your code accordingly refer here

Cheers :slight_smile:


#3

Hi @codexthon, thank you for taking the time to explain that.

I am sorry, I will make sure that I link to the exercise in future :slight_smile:


#4

You’re welcome @roseking :smiley:

No worries. Just sharing a good practice here (hope it’s not offending), it would really help much, both for you and for anyone who wanted to test to your code in their environment.

Because of how the forum (Discourse) updated recently, some part of your code get twisted. If I were to copy paste your code into my environment, I will get some syntax error which your code doesn’t have at the first place.

You can try edit your post above with code format like:

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

wrap those code with three backticks ``` before the code and after the code.

Or you can click the </> icon in the reply box when you’re replying.

Happy Coding! Cheers :smile:


#5

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