Skip to content

Commit 4e607b2

Browse files
understand and answer question
1 parent 71baeb7 commit 4e607b2

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+
29+
// 2. const penceStringWithoutTrailingP = penceString.substring(0,penceString.length - 1);
30+
// create a new variable and put the string without p
31+
32+
// 3. const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0");
33+
// padStart() adds characters to the beginning of a string to make it 3 characters long.
34+
// because we need to convert it to pound and pence
35+
36+
// 4. const pounds = paddedPenceNumberString.substring(0,paddedPenceNumberString.length - 2);
37+
// We remove the last 2 characters and store the remaining part of the string as pounds.
38+
39+
// 5. const pence = paddedPenceNumberString.substring(paddedPenceNumberString.length - 2).padEnd(2, "0");
40+
// Gets the last two characters as pence.”
41+
42+
// 6. console.log(`£${pounds}.${pence}`);
43+
//. Finally combine pound and pence

0 commit comments

Comments
 (0)