From the course: JavaScript Essential Training

Unlock the full course today

Join today to access over 23,200 courses taught by industry experts.

Solution: Calculate sales tax

Solution: Calculate sales tax - JavaScript Tutorial

From the course: JavaScript Essential Training

Solution: Calculate sales tax

(upbeat music) - [Instructor] Solving a challenge like this, it's a good idea to start by looking at what the code is already doing, so we can see how it all fits together. We'll start down here in the Test code area. So we have this prices array, which is an array of arrays of prices. Then we have a constant called randomPrices that uses Math that just generates a random response. And then down here, we have this constant called result, and the result calls in a function called showTotals that grabs the prices array and then one of the items randomly. So that's how we're passing the prices in. Okay, so we're looking for showTotals then. I'll scroll through my Answer code, and down here, we have showTotals. showTotals receives an array of prices, and then it sets up a new constant called totals and calls in calculateTotal and passes prices into that function. Whatever it gets in return, it then uses to output this…

Contents