课程: JavaScript Essential Training
今天就学习课程吧!
今天就开通帐号,24,600 门业界名师课程任您挑!
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…
随堂练习,边学边练
下载课堂讲义。学练结合,紧跟进度,轻松巩固知识。
内容
-
-
-
-
-
-
-
-
Variables: Containers for everything2 分钟 31 秒
-
(已锁定)
Var3 分钟 15 秒
-
(已锁定)
Scope3 分钟 37 秒
-
(已锁定)
Let4 分钟 34 秒
-
(已锁定)
Const2 分钟 58 秒
-
(已锁定)
Data types3 分钟 7 秒
-
(已锁定)
Assignment vs. comparison4 分钟 35 秒
-
(已锁定)
Math operators6 分钟 13 秒
-
(已锁定)
Challenge intro: Calculate sales tax1 分钟 35 秒
-
(已锁定)
Solution: Calculate sales tax3 分钟 30 秒
-
-
-
-
-
-