Skip to content

Commit 0f9ac30

Browse files
committed
Address Sprint 1 review feedback
1 parent b8c0df3 commit 0f9ac30

3 files changed

Lines changed: 31 additions & 14 deletions

File tree

Sprint-1/1-key-exercises/4-random.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ const maximum = 100;
33

44
const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum;
55

6-
// num stores a random whole number between 1 and 100.
7-
// Math.random() generates a random decimal between 0 and 1.
6+
// num stores a random whole number in the interval [1, 100].
7+
// Math.random() generates a random decimal in the interval [0, 1).
88
// Math.floor() rounds the number down to the nearest whole number.
9-
// Adding minimum ensures the final result is between 1 and 100.
9+
// Adding minimum ensures the final result is in the interval [1, 100].
10+
1011
console.log(num);

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
const cardNumber = "4533787178994213";
2-
const last4Digits = cardNumber.slice(-4);
1+
const cardNumber = 4533787178994213;
2+
const last4Digits = String(cardNumber).slice(-4);
3+
4+
console.log(last4Digits);
35

46
// The last4Digits variable should store the last 4 digits of cardNumber
57
// However, the code isn't working

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

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,26 @@ console.log(`The percentage change is ${percentageChange}`);
1111

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

14-
// a) How many function calls are there in this file? Write down all the lines where a function call is made
15-
16-
// 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?
17-
18-
// c) Identify all the lines that are variable reassignment statements
19-
20-
// d) Identify all the lines that are variable declarations
21-
22-
// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
14+
// a) There are 5 function calls.
15+
// Line 4: carPrice.replaceAll(",", "")
16+
// Line 4: Number(...)
17+
// Line 5: priceAfterOneYear.replaceAll(",", "")
18+
// Line 5: Number(...)
19+
// Line 10: console.log(...)
20+
21+
// b) There is no error in the current code because it has already been fixed.
22+
// The original error occurred because a comma was missing between the arguments in a function call.
23+
// The missing programming term is "arguments".
24+
// Adding the missing comma fixes the syntax error.
25+
26+
// c) Variable reassignment statements:
27+
// Line 4: carPrice = Number(carPrice.replaceAll(",", ""));
28+
// Line 5: priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", ""));
29+
30+
// d) Variable declarations:
31+
// Line 1: let carPrice = "10,000";
32+
// Line 2: let priceAfterOneYear = "8,543";
33+
// Line 7: const priceDifference = carPrice - priceAfterOneYear;
34+
// Line 8: const percentageChange = (priceDifference / carPrice) * 100;
35+
36+
// e) The expression Number(carPrice.replaceAll(",", "")) first removes the comma from the string "10,000", producing "10000". It then converts that string into the number 10000 so it can be used in mathematical calculations.

0 commit comments

Comments
 (0)