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
// substring(0,penceString.length - 1) this code gets all characters except the last one. so "399p" becomes just"399".
32
-
// 3: const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0") Ensures the pence string that has at least 3 digits, by padding it in left with "0" if needed for example: 399 stays 399 or 7 would become 007.
33
-
// 4: const pounds = paddedPenceNumberString.substring(0,paddedPenceNumberString.length - 2) Extracts the pound portion (except the last two one) __ "399"-"3"(pounds)
30
+
// substring(0,penceString.length - 1) this code gets all characters except the last one. so "399p" becomes just"399".
31
+
// 3: const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0") Ensures the pence string that has at least 3 digits, by padding it in left with "0" if needed for example: 399 stays 399 or 7 would become 007.
32
+
// 4: const pounds = paddedPenceNumberString.substring(0,paddedPenceNumberString.length - 2) Extracts the pound portion (except the last two one) __ "399"-"3"(pounds)
34
33
// 5: const pence = paddedPenceNumberString.substring(paddedPenceNumberString.length - 2).padEnd(2, "0") Gets the last two digits as the pence part. for example: "399"__"99"(pence)
35
34
// padEnd(2, "0") ensures at least two digits for pence.__eg: "3"_"30".
36
35
// 6: console.log(`£${pounds}.${pence}`) logs the full formatted price in pounds and pence.__eg:for "399P" pounds"3" pence"99" and the result is __ "3.99"
36
+
// Could we expect this program to work as intended for any valid penceString if we deleted .padEnd(2, "0") from the code?
37
+
// In other words, do we really need .padEnd(2, "0") in this script?
38
+
// Yes, we need `.padEnd(2, "0")` to ensure the penceString is always at least two digits long.
0 commit comments