Skip to content

Commit a36e160

Browse files
committed
completed scheduled tasks
1 parent 71c6802 commit a36e160

File tree

1 file changed

+27
-5
lines changed

1 file changed

+27
-5
lines changed

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

Lines changed: 27 additions & 5 deletions
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,33 @@ 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-
15+
/*
16+
There are 5 function calls in this file.
17+
They are on the following lines:
18+
Line 4: carPrice.replaceAll(",", "")
19+
Line 5: priceAfterOneYear.replaceAll(",", "")
20+
Line 4: Number(carPrice.replaceAll(",", ""))
21+
Line 5: Number(priceAfterOneYear.replaceAll(",", ""))
22+
Line 8: console.log(`The percentage change is ${percentageChange}`)
23+
*/
1624
// 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?
17-
25+
/*
26+
Line 5 - SyntaxError: missing , after argument list (the comma separating the arguments is missing). I added the comma.
27+
*/
1828
// c) Identify all the lines that are variable reassignment statements
19-
29+
/*
30+
Lines 4 and 5 are variable reassignment statements.
31+
carPrice = Number(carPrice.replaceAll(",", ""));
32+
priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", ""));
33+
*/
2034
// d) Identify all the lines that are variable declarations
21-
35+
/*
36+
Lines 1 and 2 are variable declarations.
37+
let carPrice = "10,000";
38+
let priceAfterOneYear = "8,543";
39+
Lines 7 and 8 are also variable declarations.
40+
const priceDifference = carPrice - priceAfterOneYear;
41+
const percentageChange = (priceDifference / carPrice) * 100;
42+
*/
2243
// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
44+
// The expression is converting the string value of carPrice, which contains a comma, into a number by first removing the comma using the replaceAll method and then converting the resulting string into a number using the Number function. This allows for mathematical operations to be performed on carPrice.

0 commit comments

Comments
 (0)