|
| 1 | +# Sprint 1 — Mandatory Interpret (Notes) |
| 2 | + |
| 3 | +## 1-percentage-change.js |
| 4 | +- What the program does: |
| 5 | +- Inputs: |
| 6 | +- Output: |
| 7 | +- Unfamiliar syntax (with link): |
| 8 | +- What I changed / why: |
| 9 | + |
| 10 | + |
| 11 | +## 2-time-format.js |
| 12 | +- What the program does: |
| 13 | +- Inputs: |
| 14 | +- Output: |
| 15 | +- Unfamiliar syntax (with link): |
| 16 | +- What I changed / why: |
| 17 | + |
| 18 | +## 3-to-pounds.js |
| 19 | +- What the program does: |
| 20 | +- Inputs: |
| 21 | +- Output: |
| 22 | +- Unfamiliar syntax (with link): |
| 23 | +- What I changed / why: |
| 24 | + |
| 25 | + |
| 26 | +## 1-percentage-change.js |
| 27 | + |
| 28 | +### a) How many function calls are there? |
| 29 | +There are 5 function calls: |
| 30 | +- Number(carPrice.replaceAll(",", "")) |
| 31 | +- carPrice.replaceAll(",", "") |
| 32 | +- Number(priceAfterOneYear.replaceAll(",", "")) |
| 33 | +- priceAfterOneYear.replaceAll(",", "") |
| 34 | +- console.log(...) |
| 35 | + |
| 36 | +--- |
| 37 | + |
| 38 | +### b) Where did the error occur and why? |
| 39 | +The error occurred on the line: |
| 40 | +priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," "")); |
| 41 | + |
| 42 | +The replaceAll function was missing a comma between its arguments. The correct syntax requires two arguments: replaceAll(search, replacement). |
| 43 | + |
| 44 | +Fix: |
| 45 | +priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", "")); |
| 46 | + |
| 47 | +--- |
| 48 | + |
| 49 | +### c) Variable reassignment statements |
| 50 | +- carPrice = Number(carPrice.replaceAll(",", "")) |
| 51 | +- priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", "")) |
| 52 | + |
| 53 | +--- |
| 54 | + |
| 55 | +### d) Variable declarations |
| 56 | +- let carPrice = "10,000" |
| 57 | +- let priceAfterOneYear = "8,543" |
| 58 | +- const priceDifference = carPrice - priceAfterOneYear |
| 59 | +- const percentageChange = (priceDifference / carPrice) * 100 |
| 60 | + |
| 61 | +--- |
| 62 | + |
| 63 | +### e) What does Number(carPrice.replaceAll(",", "")) do? |
| 64 | +First, replaceAll(",", "") removes commas from the string "10,000", producing "10000". |
| 65 | +Then, Number(...) converts the string "10000" into the numeric value 10000. |
| 66 | +This ensures arithmetic operations can be performed correctly. |
0 commit comments