-
-
Notifications
You must be signed in to change notification settings - Fork 337
Expand file tree
/
Copy path2-time-format.js
More file actions
34 lines (25 loc) · 1.77 KB
/
2-time-format.js
File metadata and controls
34 lines (25 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
const movieLength = 8784; // length of movie in seconds
const remainingSeconds = movieLength % 60;
const totalMinutes = (movieLength - remainingSeconds) / 60;
const remainingMinutes = totalMinutes % 60;
const totalHours = (totalMinutes - remainingMinutes) / 60;
const result = `${totalHours}:${remainingMinutes}:${remainingSeconds}`;
console.log(result);
// For the piece of code above, read the code and then answer the following questions
// a) How many variable declarations are there in this program?
// there are 6 variable declaration.
// b) How many function calls are there?
// One function call
// c) Using documentation, explain what the expression movieLength % 60 represents
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators
// The % operator checks the remainder of that expression when being evaluated. It is similar to the remainder theorem in mathematics.
// if it returns 0, even, if it returns value other than zero, it odd. it is mostly used for checks in programming
// d) Interpret line 4, what does the expression assigned to totalMinutes mean?
// The total time for this movie is 8760 second and fractional 24 seconds, line 4 is used to deduct the fractional 24 seconds
// Then convert the whole number seconds to minute.
// e) What do you think the variable result represents? Can you think of a better name for this variable?
// the variable result represent total movie duration in hours,minute and seconds.
// const=runningTime
// f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer
// this code works for all movie running time and integer values.
// for movie running time which are multiples of 60 it returns hours with 0 minutes and 0 seconds