File tree Expand file tree Collapse file tree 2 files changed +22
-2
lines changed
Sprint-1/3-mandatory-interpret Expand file tree Collapse file tree 2 files changed +22
-2
lines changed Original file line number Diff line number Diff line change @@ -41,7 +41,7 @@ by subtracting the remaining seconds and dividing by 60.
4141
4242
4343// e) What do you think the variable result represents? Can you think of a better name for this variable?
44- variable result represents the formatted time in hours , minutes , and seconds ( HH :MM :SS ) .
44+ variable result represents the formatted remaining movielength time in hours , minutes , and seconds ( HH :MM :SS ) .
4545
4646// f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer
4747yes this code will work for all values of movieLength asa long as it is a non - negative integers .
Original file line number Diff line number Diff line change @@ -24,4 +24,24 @@ console.log(`£${pounds}.${pence}`);
2424// Try and describe the purpose / rationale behind each step
2525
2626// To begin, we can start with
27- // 1. const penceString = "399p": initialises a string variable with the value "399p"
27+ 1. const penceString = "399p" : initialises a string variable with the value "399p"
28+ 2. const penceStringWithoutTrailingP = penceString . substring (
29+ 0 , penceString . length - 1 ) ;
30+ This line removes the trailing "p" from the pence string , leaving just the numeric value "399" .
31+
32+ 3. const paddedPenceNumberString = penceStringWithoutTrailingP . padStart ( 3 , "0" ) ;
33+ This line pads the numeric string with leading zeros to ensure it is at least 3 characters long , resulting in "0399" .
34+
35+ 4. const pounds = paddedPenceNumberString . substring (
36+ 0 ,
37+ paddedPenceNumberString . length - 2
38+ ) ;
39+ This line extracts the pounds part by taking all characters except the last two ( which represent pence ) , resulting in "03" .
40+
41+ 5. const pence = paddedPenceNumberString
42+ . substring ( paddedPenceNumberString . length - 2 )
43+ . padEnd ( 2 , "0" ) ;
44+ This line extracts the last two characters ( representing pence ) and ensures they are exactly two digits long by padding with trailing zeros if necessary , resulting in "99" .
45+
46+ 6. console . log ( `£${ pounds } .${ pence } ` ) ;
47+ This line logs the formatted price in pounds and pence , e . g . , £03 .99 .
You can’t perform that action at this time.
0 commit comments