Skip to content

Commit 2193c03

Browse files
committed
complete 1-percentage-change
1 parent d97b50e commit 2193c03

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

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

Lines changed: 8 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,18 @@ 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 3 function calls in this file. The Number() constructor is called twice on lines 4 and 5. On line 10 console.log() is also called
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+
// /home/kris/Code/CYF/ITP/Module-Structuring-and-Testing-Data/Sprint-1/3-mandatory-interpret/1-percentage-change.js:5 <-- this indicates the error is on line 5
19+
// priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," ""));
20+
// ^^^ <-- This highlights where the error is in the line. In this case the computer stops reading the code at the highlighted part because we are missing a comma after that
1721

1822
// c) Identify all the lines that are variable reassignment statements
23+
// carPrice is reassigned at line 4 and priceAfterOneYear is reassigned at line 5
1924

2025
// d) Identify all the lines that are variable declarations
26+
// Line 1 (carPrice), line 2 (priceAfterOneYear), line 7 (priceDifference) and line 8 (percentageChange)
2127

2228
// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
29+
// The replaceAll() method replaces one or more characters of a string with something different. In this case, the method just removes the comma, because the replacement value is an empty string

0 commit comments

Comments
 (0)