Skip to content

Commit 2926cd8

Browse files
committed
Refactor convert function to encapsulate logic and test with various inputs
1 parent 179fcb4 commit 2926cd8

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
const movieLength = 8784; // length of movie in seconds
1+
//const movieLength = 8784; // length of movie in seconds
2+
function convert(movieLength){
23

34
const remainingSeconds = movieLength % 60;
45
const totalMinutes = (movieLength - remainingSeconds) / 60;
@@ -8,6 +9,11 @@ const totalHours = (totalMinutes - remainingMinutes) / 60;
89

910
const result = `${totalHours}:${remainingMinutes}:${remainingSeconds}`;
1011
console.log(result);
12+
}
13+
14+
[65, -100, 90.5, "8784"].forEach(v => {
15+
console.log(v, "->", convert(v));
16+
});
1117

1218
// For the piece of code above, read the code and then answer the following questions
1319

@@ -47,4 +53,5 @@ console.log(result);
4753
// the result, 146, is the total number of complete minutes contained in the movie
4854

4955
// e) The variable 'result' is a template literal syntax which holds the movie's length formatted as a colon-separated time string: as in '2:26:24'.
50-
// A better name for 'result' could have been 'movieLengthDisplay'
56+
// A better name for 'result' could have been 'movieLengthDisplay'
57+

0 commit comments

Comments
 (0)