Skip to content

Commit 7fdaec0

Browse files
committed
Breakdwon the code
1 parent 69b5489 commit 7fdaec0

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const penceStringWithoutTrailingP = penceString.substring(
44
0,
55
penceString.length - 1
66
);
7+
//
78

89
const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0");
910
const pounds = paddedPenceNumberString.substring(
@@ -24,4 +25,14 @@ console.log(`£${pounds}.${pence}`);
2425
// Try and describe the purpose / rationale behind each step
2526

2627
// To begin, we can start with
27-
// 1. const penceString = "399p": initialises a string variable with the value "399p"
28+
// 1. const penceString = "399p": initialises a string variable with the value "399p".
29+
30+
// 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.
31+
32+
// 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.
33+
34+
// 4. const pounds = paddedPenceNumberString.substring( 0,paddedPenceNumberString.length - 2): Takes the substring from the start up to (but not including) the last two characters.
35+
36+
// 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.
37+
38+
// 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)