Skip to content

Commit 555030a

Browse files
Address reviewer feedback for Sprint 1
1 parent 86d2a18 commit 555030a

4 files changed

Lines changed: 17 additions & 11 deletions

File tree

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,8 @@ const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum;
1010
// It will help to think about the order in which expressions are evaluated
1111
// Try logging the value of num and running the program several times to build an idea of what the program is doing
1212

13-
// Math.random() generates a random decimal,
14-
// Math.floor() rounds it down, and the expression produces a random whole number between 1 and 100.
13+
// Math.random() creates a random decimal number.
14+
// The number will always be between 0 and 1, but it will never actually reach 1.
15+
16+
// Math.floor() rounds down the decimal number that is created after
17+
// Math.random() is multiplied by the range.

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 @@
11
const cardNumber = 4533787178994213;
2-
const last4Digits = cardNumber.slice(-4);
2+
// I fixed the error by replacing the original expression instead of declaring
3+
// last4Digits a second time. Declaring a const twice causes a SyntaxError.
4+
const last4Digits = cardNumber % 10000;
35

46
// The last4Digits variable should store the last 4 digits of cardNumber
57
// However, the code isn't working
@@ -14,4 +16,4 @@ const last4Digits = cardNumber.slice(-4);
1416
// The error is what I predicted. The slice method is not a function that can be used on numbers, only strings.
1517

1618
// Then try updating the expression last4Digits is assigned to, in order to get the correct value
17-
const last4Digits = cardNumber % 10000;
19+

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,14 @@ console.log(`The percentage change is ${percentageChange}`);
1818
// Line 10 calls console.log().
1919

2020
// 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?
21-
// The error was on line 5. The replaceAll() function call was missing the correct closing bracket/parenthesis.
22-
// I fixed it by making the line: priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", ""));
21+
// I changed the value from a string to a number by wrapping the replaceAll() result in Number().
2322

2423
// c) Identify all the lines that are variable reassignment statements
2524
// Lines 4 and 5 are variable reassignment statements because its declared on lines 1 and 2.
2625

2726

2827
// d) Identify all the lines that are variable declarations
29-
// line 1 and 2 are variable declarations because they are declared using the let keyword.
28+
// Lines 1, 2, 7, and 8 are variable declarations because they declare variables using let and const.
3029

3130
// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
3231
//// Removes commas and converts the string to a number.

Sprint-1/3-mandatory-interpret/2-time-format.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const movieLength = 8784; // length of movie in seconds
1+
const movieLength = 3665; // length of movie in seconds
22

33
const remainingSeconds = movieLength % 60;
44
const totalMinutes = (movieLength - remainingSeconds) / 60;
@@ -32,8 +32,10 @@ result */
3232
// This gives us the total number of whole minutes in the movie length.
3333

3434
// e) What do you think the variable result represents? Can you think of a better name for this variable?
35-
// The variable result represents the total length of the movie in hours, minutes, and seconds.
36-
// A better name for this variable could be "movieDuration".
35+
// The variable result stores the movie duration as a formatted string (hours:minutes:seconds).
36+
// A better name would be "formattedMovieLength".
3737

3838
// f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer
39-
// The code works for non-negative whole numbers. Negative or decimal values may produce incorrect or unexpected results.
39+
// The code works when movieLength is 3665. It outputs "1:1:5", which is correct,
40+
// but the formatting is not ideal. A better formatted output would be "1:01:05".
41+
// The code works for whole numbers, but it does not pad single-digit minutes and seconds with leading zeros.

0 commit comments

Comments
 (0)