Skip to content

Commit ba2b449

Browse files
This commit is for section 3 of sprint 1 brach
1 parent 20fb215 commit ba2b449

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

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

Lines changed: 28 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;
@@ -20,3 +20,30 @@ console.log(`The percentage change is ${percentageChange}`);
2020
// d) Identify all the lines that are variable declarations
2121

2222
// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
23+
24+
/*
25+
Answer
26+
a) In this section of the code, we have function calls appear 5 time through out the code. Here is each of them on the line of code that
27+
they are call:
28+
- Number(carPrice.replaceAll(",","")); in line 4 is a function calls because the .replaceALL is being executed
29+
- Number(priceAfterOneYear.replaceAll(",", "")); in line 5 is also a function call because .replaceAll is being executed.
30+
- Inside the Number() function the .replaceAll in both line 4 and 5 is also a function call because the the parent function is also
31+
being executed.
32+
- the console.log is a function calls
33+
So the total amount of function call in this code is 5
34+
35+
b) The main error for the when the running this line of code if for the missing right parameter after the double quote, so fix this
36+
just add the coma right after the double quote.
37+
38+
c) There are 2 reassign variable statement at line 4 and line 5.
39+
40+
d)There are 4 total variable declarations in this code:
41+
- let carPrice = "10,00"; line 1
42+
- let priceAfterOneYear ="8,543"; line 2
43+
- const priceDifference = carPrice - priceAfterOneYear; line 7
44+
- const percentageChange = (priceDifference / carPrice) * 100; line 8
45+
46+
e) The expression Number(carPrice.replaceAll(",","")) are doing 2 main purpose,
47+
- The first purpose is to remove the coma from the string number "10000" and "8543".
48+
- Is the changing the string number to number data type.
49+
*/

0 commit comments

Comments
 (0)