Skip to content

Commit b9f2f51

Browse files
committed
Identify function calls, errors, variable declarations/reassignments, and explain Number(...replaceAll(...)) usage
1 parent 4aaf415 commit b9f2f51

File tree

1 file changed

+8
-2
lines changed

1 file changed

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

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

77
const priceDifference = carPrice - priceAfterOneYear;
88
const percentageChange = (priceDifference / carPrice) * 100;
@@ -12,11 +12,17 @@ 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 five function calls in this file. function was called on line 4 (twice), line 5 (twice) and line 10.
1516

1617
// 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?
18+
// Answer:
19+
// After running the code, the error occurred because a comma was missing between the quotation marks on line 5. I fixed it by adding the missing comma.
1720

1821
// c) Identify all the lines that are variable reassignment statements
22+
// Answer: Variable reassignment statements occurred on lines 4 and 5
1923

2024
// d) Identify all the lines that are variable declarations
25+
// Answer: Variable declarations occurred on lines 1, 2, 7, and 8.
2126

2227
// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
28+
// Answer: The .replaceAll() method runs first to find all the comma in the variable carPrice and replace them with nothing then the Number() functions runs to convert the value to a number data type

0 commit comments

Comments
 (0)