Skip to content

Commit 4ad9366

Browse files
committed
added another edgecase to time formatting
1 parent 7d1a29e commit 4ad9366

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

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

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

33
const remainingSeconds = movieLength % 60;
44
const totalMinutes = (movieLength - remainingSeconds) / 60;
55

66
const remainingMinutes = totalMinutes % 60;
77
const totalHours = (totalMinutes - remainingMinutes) / 60;
88

9-
const result = `${totalHours}:${remainingMinutes}:${remainingSeconds}`;
9+
const result = `${totalHours}:${String(remainingMinutes).padStart(2, "0")}:${String(remainingSeconds).padStart(2, "0")}`;
1010
console.log(result);
1111

1212
// For the piece of code above, read the code and then answer the following questions
@@ -33,4 +33,5 @@ console.log(result);
3333
// f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer
3434
// No. Not for all possible values of movieLength, some EdgeCases are:
3535
//1. when movieLength is of negative value, the maths produces negative time and its illogical for a movie duration
36-
//2. if movieLength is not a number, its produces "NAN" and this breaks mathematically
36+
//2. if movieLength is not a number, its produces "NAN" and this breaks mathematically
37+
//3. what if movieLength is less than 10? if movieLength is let say 9 , without proper formatting it will look like this 0:0:9 but with 0 padding it looks better like this 0:00:09

Sprint-1/3-mandatory-interpret/3-to-pounds.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,7 @@ console.log(`£${pounds}.${pence}`);
2424
// Try and describe the purpose / rationale behind each step
2525

2626
// To begin, we can start with
27-
// 1. const penceString = "399p": initialises a string variable with the value "399p"
27+
/* 1. const penceString = "399p": initializes a string variable with the value "399p"
28+
2. const penceStringWithoutTrailingP = This stores the substring of penceString without a trailing p, so "399p" becomes "399"
29+
3. const paddedPenceNumberString=
30+
*/

0 commit comments

Comments
 (0)