Skip to content

Commit 5eb5f21

Browse files
committed
check code by running
1 parent f5499b3 commit 5eb5f21

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,18 @@ 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(0, penceString.length - 1); : a variable declared and a function called
29+
// in the variable with substring method. In the substring method (penceString.length - 1) = 4 -1 = 3 then the function remains
30+
// penceString.substring(0, 3); from which we find const penceStringWithoutTrailingP = 399p.penceString.substring(0, 3); to
31+
// const penceStringWithoutTrailingP = 399
32+
// 3. const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0");
33+
// const pounds = paddedPenceNumberString.substring(0, paddedPenceNumberString.length - 2); : another variable const paddedPenceNumberString
34+
// declared and a function called in the variable with padStart method. penceStringWithoutTrailingP.padStart(3, "0"); will be 399.padStart(3, "0");
35+
// and finally const paddedPenceNumberString = "399". Secondly, another variable const pounds declared in which calculates the value in
36+
// pounds. For this, (0, paddedPenceNumberString.length - 2); will be (0, 1) and the const pounds = 399.substring(0, 1); calculates
37+
// const pounds = 3
38+
// 4. const pence = paddedPenceNumberString.substring(paddedPenceNumberString.length - 2).padEnd(2, "0"); : a variable pence declared
39+
// to calculate the value in pence. so, if we put the values it will be const pence = 399.substring(1).padEnd(2, "0"); which at first works for
40+
// substring and then for padEnd and will be const pence = 99;
41+
// 5. console.log(`£${pounds}.${pence}`); : this console function printed the prince in pounds and pence.And finally the printed output
42+
// will be £3.99

0 commit comments

Comments
 (0)