This repository was archived by the owner on Apr 18, 2025. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 49
Expand file tree
/
Copy pathtime-format.js
More file actions
44 lines (28 loc) · 1.51 KB
/
time-format.js
File metadata and controls
44 lines (28 loc) · 1.51 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
35
36
37
38
39
40
41
42
43
44
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 remainingHours = totalHours % 24;
const result = `${remainingHours}:${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?
//ans; Their is no variable declarations.
// b) How many function calls are there?
//ans; 1 function, console.log
// c) Using documentation on MDN, explain what the expression movieLength % 60 represents
//ans; the remainder of the division of movieLength by 60
// d) Interpret line 4, what does the expression assigned to totalMinutes mean?
//ans; the total remainingSeconds is in integer.
// e) What do you think the variable result represents? Can you think of a better name for this variable?
//ans; the length of move in hours minutes and seconds. can be length.
//ans; it will bring an output result of 2 : 26: 24
// f) Think about whether this program will work for all values of movieLength.
//ans ; yes
// Think of what values may cause problems for the code.
// ans; infinity
// Decide the result should be for those values, then test it out.
// ans; the results undefine
// Can you find any values of movieLength which don't give you what you'd expect?
//ans; no