Skip to content

Commit 774c424

Browse files
authored
Describe the code
1 parent 5ae96f4 commit 774c424

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

Sprint-1/3-mandatory-interpret/3-to-pounds.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,9 @@ 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(0,penceString.length - 1): represent to takes a substring from index 0 up to (but not including) penceString.length - 1.
29+
// 3. const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"): assign to ensures the numeric string is at least 3 characters long by adding leading zeros if needed.
30+
// 4. const pounds = paddedPenceNumberString.substring( 0,paddedPenceNumberString.length - 2): Takes the substring from the start up to (but not including) the last two characters.
31+
// 5. substring(length - 2) : use to returns the last two characters (the pence digits). padEnd(2, "0") would append trailing zeros if the result were shorter than 2.
32+
// 6. console.log(`£${pounds}.${pence}`): assign to display the price in a human-readable pounds-and-pence format (£x.yy)

0 commit comments

Comments
 (0)