@@ -63,4 +63,54 @@ priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", ""));
6363### e) What does Number(carPrice.replaceAll(",", "")) do?
6464First, replaceAll(",", "") removes commas from the string "10,000", producing "10000".
6565Then, Number(...) converts the string "10000" into the numeric value 10000.
66- This ensures arithmetic operations can be performed correctly.
66+ This ensures arithmetic operations can be performed correctly.
67+
68+
69+
70+ ## 2-time-format.js
71+
72+ ### a) How many variable declarations?
73+ There are 6 variable declarations:
74+ - movieLength
75+ - remainingSeconds
76+ - totalMinutes
77+ - remainingMinutes
78+ - totalHours
79+ - result
80+
81+ ---
82+
83+ ### b) How many function calls?
84+ There is 1 function call:
85+ - console.log(result)
86+
87+ ---
88+
89+ ### c) What does movieLength % 60 represent?
90+ The % operator returns the remainder after division.
91+ movieLength % 60 gives the number of seconds left after converting full minutes.
92+ In this example, it returns 24 seconds.
93+
94+ ---
95+
96+ ### d) Interpret line 4 (totalMinutes)
97+ const totalMinutes = (movieLength - remainingSeconds) / 60;
98+
99+ This subtracts the leftover seconds from the total seconds and divides by 60.
100+ The result is the total number of full minutes in the movie.
101+
102+ ---
103+
104+ ### e) What does result represent? Better name?
105+ The variable result represents the formatted movie duration in hours:minutes: seconds .
106+ A better name could be:
107+ - formattedTime
108+ - movieDuration
109+ - durationString
110+
111+ ---
112+
113+ ### f) Will this work for all values of movieLength?
114+ Yes, it works for any positive number of seconds.
115+ However, if movieLength is negative, a decimal, or not a number, the result would be incorrect.
116+ Also, minutes and seconds are not padded with leading zeros, so values like 2:3:5 may appear instead of 02:03:05.
0 commit comments