Skip to content

Commit 14e15a6

Browse files
committed
percentage exercise is completed
1 parent d51395c commit 14e15a6

File tree

2 files changed

+51
-4
lines changed

2 files changed

+51
-4
lines changed

Sprint-1/2-mandatory-errors/4.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,7 @@
1-
const 12HourClockTime = "20:53";
2-
const 24hourClockTime = "08:53";
1+
const twelveHourClockTime = "08:53";
2+
const twentyFourHourClockTime = "20:53";
3+
4+
//tha variable names are cannot start with a number
5+
// so the variable name 12HourClockTime is not valid because it starts with a number
6+
// to fix this error we can change the variable name to twelveHourClockTime and as is not relevant to the time format
7+
// so we can swap the variable names.

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

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,63 @@ 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;
99

10-
console.log(`The percentage change is ${percentageChange}`);
10+
console.log(`The percentage change is ${percentageChange} %`);
1111

1212
// Read the code and then answer the questions below
1313

14+
15+
1416
// a) How many function calls are there in this file? Write down all the lines where a function call is made
1517

18+
/*There are four function calls in total: two in the line
19+
20+
carPrice = Number(carPrice.replaceAll(",", ""));
21+
22+
and two in the line
23+
24+
priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," ""));
25+
26+
In each line, one function is nested inside the other, so both lines contain two function calls each.*/
27+
28+
29+
1630
// 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?
1731

32+
33+
/*priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," ""));
34+
^^^
35+
36+
SyntaxError: missing ) after argument list
37+
the error is because a missing comma in the replaceAll method argument list
38+
*/
39+
40+
1841
// c) Identify all the lines that are variable reassignment statements
1942

43+
44+
45+
/*carPrice = Number(carPrice.replaceAll(",", ""));
46+
priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," ""));
47+
these two lines are variable reassignment statements because we are reassigning a new value to the existing variables carPrice and priceAfterOneYear.*/
48+
2049
// d) Identify all the lines that are variable declarations
2150

51+
52+
/*let carPrice = "10,000";
53+
let priceAfterOneYear = "8,543";
54+
const priceDifference = carPrice - priceAfterOneYear;
55+
const percentageChange = (priceDifference / carPrice) * 100;
56+
57+
these four lines are variable declaration statements because we are declaring new variables:
58+
carPrice, priceAfterOneYear, priceDifference and percentageChange using let and const keywords.*/
59+
60+
61+
2262
// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
63+
64+
/*first removes all commas from the string carPrice using replaceAll(",", ""), and then converts the resulting string into a number using Number().*/

0 commit comments

Comments
 (0)