Skip to content

Commit 974ed0e

Browse files
committed
complete 3-to-pounds
1 parent 82c02c0 commit 974ed0e

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,14 @@ 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+
29+
// 3. const penceStringWithoutTrailingP = penceString.substring( 0, penceString.length - 1) <-- removes the last character from penceString (p) and assign the resulting value to a new variable penceStringWithoutTrailingP
30+
31+
// 8. const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0") <-- using padStart, ensures the string is at least 3 characters. In case of the string being less than 3 characters, padStart will add "0" at the beginning until it reaches the required length. The resulting string is assigned to a new variable paddedPenceNumberString
32+
33+
// 9. const pounds = paddedPenceNumberString.substring(0, paddedPenceNumberString.length - 2) <-- uses the substring() method to create a new string from paddedPenceNumberString without the last 2 characters. This new string is then assigned to the new variable pounds
34+
35+
// 14. const pence = paddedPenceNumberString.substring(paddedPenceNumberString.length - 2).padEnd(2, "0") <-- takes the last two characters of paddedPenceNumberString and creates a new string that is then assigned to the variable pence. The padEnd() method, which ensures a length of 2 characters by adding a "0" at the end, seems to be redundant, as substring is already returning 2 characters, so the 0 will never be added.
36+
37+
// 18. console.log(`£${pounds}.${pence}`) <-- uses template literals to create a string by putting together "£", the pound amount, "." and the pence amount. Then string is then printed in the terminal with console.log()

0 commit comments

Comments
 (0)