Skip to content

Commit 7dd742e

Browse files
committed
explained the code line by line
1 parent 9080a92 commit 7dd742e

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,22 @@ 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+
//
29+
// 3.const penceStringWithoutTrailingP = penceString.substring(
30+
// 0,
31+
// penceString.length - 1
32+
// ); assigned the string to a new variable with out the P - by using the substring method - the .length will count the number of the characters and only display 1 before last
33+
//
34+
// 8. const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0");
35+
// using the pedStart method we ensure to fill the gas - we can add 0 on this occasion to our string beginning the the number of length does not match with 3 characters - fill in the gaps
36+
// 9. const pounds = paddedPenceNumberString.substring(
37+
// 0,
38+
// paddedPenceNumberString.length - 2
39+
//); again we create a new variable to only store the first character of the string
40+
//
41+
// 14. const pence = paddedPenceNumberString
42+
// .substring(paddedPenceNumberString.length - 2)
43+
// .padEnd(2, "0");
44+
// creating a new variable to assign only the last two character of the string - we also use the padEnd method to fill the end gaps with zeros
45+
//
46+
// 18. we call the newly created variables with consol.log to display this as a new string on the console

0 commit comments

Comments
 (0)