You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// num is generating a random dicimal number with method Math.random() between 0 and 1 result eg :0.3948605
15
15
16
-
17
-
18
16
//Second operation
19
17
//The generated number is multiplied by the range+1 which is between 1-100 result eg 39.48605
20
18
19
+
//Third operation
20
+
//num is rounded down to the nearset whole number using the method Math.floor restult eg 39.48605 => 39
21
21
22
-
//Third operation
23
-
//num is rounded down to the nearset whole number using the method Math.floor restult eg 39.48605 => 39
24
-
25
-
26
-
27
-
// Last operation is to add the "minimum" (in this case it's 1 or it can be changed to any changed number e.g 10) this will shift the random number so it starts counting from minimum, instead of from zero.
28
-
//eg . num was 39 => 40
22
+
// Last operation is to add the "minimum" (in this case it's 1 or it can be changed to any changed number e.g 10) this will shift the random number so it starts counting from minimum, instead of from zero.
/* The totalMinutes expression is calaculated first by subtrackting the lengh of movie by the reminder of seconds which rounds down the nearst minutes */
44
-
/* Since we know the total number of seconds that are multiple of 60 we can can calculate the total number of minutes by dividing it over 60 since 1 minute is 60 seconds */
45
-
/* This way we have the Movie total exact number of miutes. */
/* The totalMinutes expression is calaculated first by subtrackting the lengh of movie by the reminder of seconds which rounds down the nearst minutes */
39
+
/* Since we know the total number of seconds that are multiple of 60 we can can calculate the total number of minutes by dividing it over 60 since 1 minute is 60 seconds */
40
+
/* This way we have the Movie total exact number of miutes. */
/* - giving a negative value for movieLength will result in a negative clock: so there could have message that reject negative numbers. */
68
-
/* - The program should have represented Hours/Min/Sec in this format 00:00:00 so each time should be represented with 2 digits. */
69
-
/* - 25 hours exeeds 24 hours which represents a day so a variable total days could be added to represent time in days. */
70
-
/* -Values with dicimal numbers will return the clock showing dicimal numbers this should be rounded up or down to the nearst time with an integer number */
/* - giving a negative value for movieLength will result in a negative clock: so there could have message that reject negative numbers. */
62
+
/* - The program should have represented Hours/Min/Sec in this format 00:00:00 so each time should be represented with 2 digits. */
63
+
/* - 25 hours exeeds 24 hours which represents a day so a variable total days could be added to represent time in days. */
64
+
/* -Values with dicimal numbers will return the clock showing dicimal numbers this should be rounded up or down to the nearst time with an integer number */
// 1. const penceString = "399p": initialises a string variable with the value "399p"
29
30
// 2. penceStringWithoutTrailingP = penceString.substring( 0, penceString.length - 1): This line of code slice the penceString varible by removing the "p" character from it.
30
-
// 3. const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0") : This line of code adds "0" if lenght of penceStringWithoutTrailingP is less then 3 i.e e value is "1" => it will convert it to"001" or ifthe value is "22" it will confert it to "022".
31
+
// 3. const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0") : This line of code adds "0" if lenght of penceStringWithoutTrailingP is less then 3 i.e e value is "1" => it will convert it to"001" or ifthe value is "22" it will convert it to "022".
31
32
// 4. const pounds = paddedPenceNumberString.substring( 0, paddedPenceNumberString.length - 2); : This line of code extract and store the value of pound from paddedPenceNumberString using the substring method since £1 = 100 pences => any number in the hudered position i.e third character from the right onwards has a value of £.
32
33
// 5. const pence = paddedPenceNumberString .substring(paddedPenceNumberString.length - 2) .padEnd(2, "0");: This line of code extract and store the value of pences paddedPenceNumberString using the substring method => instead of starting from the left it start from the right moving two positions then it adds "0"in case the pences value is less then 10.
33
-
// 6. console.log(`£${pounds}.${pence}`): This line of code prints the final result in $ and pences in nice readable way => £3.99
34
+
// 6. console.log(`£${pounds}.${pence}`): This line of code prints the final result in £ and pences in nice readable way => £3.99
0 commit comments