Skip to content

Commit 948d792

Browse files
author
russom
committed
Each line of code explained.
1 parent dc16f8d commit 948d792

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,16 @@ 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+
// Answers
30+
// 1) variable const penceStringWithoutTrailingP stores the value of only the pennies part without the p.
31+
// This is done first with penceString.length -1 removes the last index of pence string (p).
32+
// Then penceString.substring(0) returns the characters from 0 to 2 of the indexes(399)
33+
34+
// 2) paddedPenceNumberString adds 0 at the beginning until the string is 3 characters long to penceStringWithoutTrailingP variable
35+
36+
// 3) pounds stores 3 by first paddedPenceNumberString.length - 2 removing index 1 and 2. Then paddedPenceNumberString.substring(0) returning index 0.
37+
38+
// 4) pence store the pennies first .length starting from index 1 then padEnd adding 0 to characters that less than 2 counts.
39+
40+
// 5) console.log prints out the final result adding a £ sign at the beginning and a . between pounds and pence.

0 commit comments

Comments
 (0)