Skip to content

Commit 4922e00

Browse files
-add missing comma between arguments in replaceAll() on line 5
-identify function calls, declarations, aand reassignments. -verify my code is working when I run console.log()
1 parent 2fc4870 commit 4922e00

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

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

Lines changed: 12 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;
@@ -12,11 +12,22 @@ console.log(`The percentage change is ${percentageChange}`);
1212
// Read the code and then answer the questions below
1313

1414
// a) How many function calls are there in this file? Write down all the lines where a function call is made
15+
// ANSWER: There are 5 function calls along 3 lines
16+
// Line 4: replaceAll() and Number()
17+
// Line 5: replaceAll() and Number()
18+
// Line 10: console.log()
1519

1620
// b) Run the code and identify the line where the error is coming from - why is this error occurring? How can you fix this problem?
21+
// ANSWER: The error comes from Line 5 because a comma is missing between the two string arguments in replaceAll("," "").
22+
// FIX: Add the missing comma to replaceAll(",", "")
1723

1824
// c) Identify all the lines that are variable reassignment statements
25+
// ANSWER: Lines 4 and 5 (carPrice and priceAfterOneYear)
1926

2027
// d) Identify all the lines that are variable declarations
28+
// ANSWER: Lines 1, 2, 7, and 8 (using let and const)
2129

2230
// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
31+
// ANSWER: The expression Number(carPrice.replaceAll(",","")) removes the comma from the carPrice = "10,000" and converts it to "10000".
32+
// Then, JavaScript can now convert the string into a number so it can be calculated.
33+

0 commit comments

Comments
 (0)