Skip to content

Commit fa5c077

Browse files
Add interpretation answers for 1-percentage-change.js
1 parent 0707b11 commit fa5c077

1 file changed

Lines changed: 23 additions & 1 deletion

File tree

‎Sprint-2/3-mandatory-interpret/1-percentage-change.js‎

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ let carPrice = "10,000";
22
let priceAfterOneYear = "8,543";
33

44
carPrice = Number(carPrice.replaceAll(",", ""));
5-
priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," ""));
5+
priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", ""));
66

77
const priceDifference = carPrice - priceAfterOneYear;
88
const percentageChange = (priceDifference / carPrice) * 100;
@@ -20,3 +20,25 @@ console.log(`The percentage change is ${percentageChange}`);
2020
// d) Identify all the lines that are variable declarations
2121

2222
// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
23+
24+
// a) I found 5 places where the code "calls" a function (runs a built-in command):
25+
// Line 4: Number(...) and carPrice.replaceAll(...)
26+
// Line 5: Number(...) and priceAfterOneYear.replaceAll(...)
27+
// Line 10: console.log(...)
28+
//
29+
// b) The error showed up on Line 5. It said "SyntaxError: missing ) after
30+
// argument list". That just means I had one too many closing brackets ( ) )
31+
// at the end of that line.
32+
//
33+
// c) There are 2 lines where a variable gets a new value (reassignment):
34+
// Line 4: carPrice = ...
35+
// Line 5: priceAfterOneYear = ...
36+
//
37+
// d) There are 4 lines where a new variable is created (declaration):
38+
// Line 1, Line 2, Line 7, and Line 8.
39+
//
40+
// e) Number(carPrice.replaceAll(",", "")) does two things, step by step:
41+
// First, replaceAll(",", "") takes out all the commas from the text, so
42+
// "10,000" turns into "10000".
43+
// Then, Number(...) changes that text into a real number (10000), so we
44+
// can do maths with it instead of treating it like a word.

0 commit comments

Comments
 (0)