Skip to content

Commit e87bd36

Browse files
committed
to_pound commit
1 parent 8d7e2e4 commit e87bd36

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,10 @@ console.log(`£${pounds}.${pence}`);
2525

2626
// To begin, we can start with
2727
// 1. const penceString = "399p": initialises a string variable with the value "399p"
28+
// 2. const penceStringWithoutTrailingP = "399p".substring( 0, penceString.length - 1): Here we use the subString method which will slide the string of
29+
// penceString starting at index 0 and ending at index 2 (3 - 1). The result should be "399"
30+
// 3. const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"): Here we want to make sure that the penceStringWithoutTrailingP variable has at least 3 characters, if that is not the case, we will add "0" infront of the character till it reaches the length required.
31+
// Here, paddedPenceNumberString = "399" . Then pounds = "3"
32+
// 4. const pence = paddedPenceNumberString.substring(paddedPenceNumberString.length - 2).padEnd(2, "0") : The substring(paddedPenceNumberString.length - 2) will return 99 and the padEnd(2,"0") will make sure that there are at least two characters here.
33+
34+

0 commit comments

Comments
 (0)