Skip to content

Commit 7d4af4e

Browse files
committed
Line by line explanation of the code
1 parent 4be47f2 commit 7d4af4e

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

‎Sprint-2/3-mandatory-interpret/3-to-pounds.js‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,19 @@ 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 = penceString.substring(
29+
// 0,
30+
//penceString.length - 1 :Removes the letter p from the end of the string.
31+
//);
32+
// 3. const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"); : Makes sure that the string has at least 3 characters by adding zeros at the beginning if required.
33+
34+
// // const pounds = paddedPenceNumberString.substring(
35+
// 0,
36+
// paddedPenceNumberString.length - 2 :This takes the first digit of the number in pence since 100 pence = 1 pound therefore coverting pence to pounds
37+
// );
38+
39+
// const pence = paddedPenceNumberString
40+
// .substring(paddedPenceNumberString.length - 2): Takes the pence which is the 2 numbers after the 1st number and ensures that it is exactly 2 digits long.
41+
// .padEnd(2, "0");
42+
43+
// console.log(`£${pounds}.${pence}`); : Prints the final output string using the literal to combine currency symbol, pounds and the pence.

0 commit comments

Comments
 (0)