Skip to content

Commit e3bf82a

Browse files
solving exercise 3-to-pounds
1 parent 7e1fd30 commit e3bf82a

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@ const penceStringWithoutTrailingP = penceString.substring(
66
);
77

88
const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0");
9-
const pounds = paddedPenceNumberString.substring(
10-
0,
9+
10+
const pounds = paddedPenceNumberString.substring( 0,
1111
paddedPenceNumberString.length - 2
1212
);
13+
console.log(pounds)
1314

1415
const pence = paddedPenceNumberString
1516
.substring(paddedPenceNumberString.length - 2)
@@ -25,3 +26,8 @@ console.log(`£${pounds}.${pence}`);
2526

2627
// To begin, we can start with
2728
// 1. const penceString = "399p": initialises a string variable with the value "399p"
29+
// 2. penceStringWithoutTrailingP = penceString.substring( 0, penceString.length - 1): This line of code slice the penceString varible by removing the "p" character from it.
30+
// 3. const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0") : This line of code adds "0" if lenght of penceStringWithoutTrailingP is less then 3 i.e e value is "1" => it will convert it to"001" or ifthe value is "22" it will confert it to "022".
31+
// 4. const pounds = paddedPenceNumberString.substring( 0, paddedPenceNumberString.length - 2); : This line of code extract and store the value of pound from paddedPenceNumberString using the substring method since £1 = 100 pences => any number in the hudered position i.e third character from the right onwards has a value of £.
32+
// 5. const pence = paddedPenceNumberString .substring(paddedPenceNumberString.length - 2) .padEnd(2, "0");: This line of code extract and store the value of pences paddedPenceNumberString using the substring method => instead of starting from the left it start from the right moving two positions then it adds "0"in case the pences value is less then 10.
33+
// 6. console.log(`£${pounds}.${pence}`): This line of code prints the final result in $ and pences in nice readable way => £3.99

0 commit comments

Comments
 (0)