Skip to content
Advertisement

How come I am unable to get the output for tax for my code?

Write a function to compute the discount and tax when you pay for a shopping items in a shop. Discount is 20% if the total order > $200, else the discount is 0. Tax is 7% of the total order after discount.

JavaScript

Advertisement

Answer

Your problem is you’re not returning anything after else. You set tax to equal something, but you don’t return it.

The following will get you the output that you’re expecting.

JavaScript

However, it should be noted, there is a lot odd about what you’re doing. Why is the total hard-coded inside the function? Why are you returning the values as non-associative array? This has the potential of getting really confusing really fast.

I’d recommend doing something like this.

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement