Skip to content

Commit 8fb4c57

Browse files
committed
All questions answered and code corrected
1 parent 6ce8a2e commit 8fb4c57

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

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

Lines changed: 16 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,26 @@ 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+
// There are 5 function calls in this file: lines 3, 4 and 7
16+
// Line 4: carPrice,replaceAll(",", "") removes all commas from string
17+
// Line 4: Number(...) converts string into number
18+
// Line 5: priceAfterOneYear.replaceAll("," "") removes all commas from string
19+
// Line 5: Number(...) converts string to number
20+
// Line 10: console.log(`The percentage change is ${percentageChange}`) prints percentage change to output
1521

1622
// 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?
23+
// Line 5 is missing a comma in the replaceAll function call. This is causing a syntax error because the function expects two arguments, but only one is provided.
1724

1825
// c) Identify all the lines that are variable reassignment statements
26+
// Variable reassignment means giving an existing variable a new value.
27+
// Lines 4 and 5 reassign new values to carPrice and priceAfterOneYear respectively.
1928

2029
// d) Identify all the lines that are variable declarations
30+
// Variable declaration means creating a new variable and assigning it a value for the first time.
31+
// Line 1 declares carPrice with let
32+
// Line 2 declares priceAfterOneYear with let
33+
// Line 7 declares priceDifference with const
34+
// Line 8 declares percentageChange with const
2135

2236
// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
37+
// It converts the string value of carPrice into a number value and removes the comma.

0 commit comments

Comments
 (0)