Skip to content

Commit 98f4de9

Browse files
Fix missing comma in replaceAll
1 parent 587429d commit 98f4de9

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,21 @@ 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;
99

1010
console.log(`The percentage change is ${percentageChange}`);
1111

12+
//a) There are 4 function calls in this file. They are on lines 1, 2, 4, and 5.
13+
//b) The error is in line 4 and 5. The error is occurring because the replaceAll function is being called on a string,
14+
// but the string has not been converted to a number.
15+
//c) The variable reassignment statements are in lines 4 and 5
16+
//d) The variable declarations are in lines 1,2,7, and 8.
17+
//e) The expression Number(carPrice.replaceAll(",","")) is converting the string carPrice into a number
18+
// by removing the commas and then converting the resulting string into a number. from "10,000" to "10000" to 10000
19+
1220
// Read the code and then answer the questions below
1321

1422
// a) How many function calls are there in this file? Write down all the lines where a function call is made

0 commit comments

Comments
 (0)