Skip to content

Commit ecc906b

Browse files
committed
code identified, error solved, questions answered
1 parent 5df6d91 commit ecc906b

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

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

Lines changed: 19 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,29 @@ 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+
// -) functions called are:
16+
// Number() ||| carPrice = Number(carPrice.replaceAll(",", ""));
17+
// Number() ||| priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," ""));
18+
// replaceAll() ||| carPrice = Number(carPrice.replaceAll(",", ""));
19+
// replaceAll() ||| priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," ""));
20+
// console.log()||| console.log(`The percentage change is ${percentageChange}`);
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+
// The error is coming from line: 5.
24+
// This error is occurring because a , is missing inside the replaceAll() so the two inputs aren't separated.
25+
// I will fix this error by adding , after the first input inside replaceAll()
26+
// replaceAll("," "") Changed to >>
27+
// replaceAll(",", "")
1728

1829
// c) Identify all the lines that are variable reassignment statements
30+
// Line 4
31+
// Line 5
1932

2033
// d) Identify all the lines that are variable declarations
34+
// Line 1
35+
// Line 2
36+
// Line 7
37+
// Line 8
2138

2239
// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
40+
// it replaces the , that is inside the number with nothing ( removes the , from the number)

0 commit comments

Comments
 (0)