Skip to content

Commit 28d4987

Browse files
answered the questions
1 parent 705d9fb commit 28d4987

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const pounds = paddedPenceNumberString.substring(
1111
paddedPenceNumberString.length - 2
1212
);
1313

14+
1415
const pence = paddedPenceNumberString
1516
.substring(paddedPenceNumberString.length - 2)
1617
.padEnd(2, "0");
@@ -25,3 +26,23 @@ 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+
30+
//2. const penceStringWithoutTrailingP = penceString.substring(0, penceString.length - 1):
31+
// removes the last character "p" from the string to get just the number part of the price in pence
32+
33+
//3. const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"):
34+
// checks if the number is 3 digits and if it is less than 3 digits adds leading zeros to make it 3 digits long
35+
// if it is less than 3 digits long it adds leading zeros ie if 5p it would become 005
36+
37+
//4. const pounds = paddedPenceNumberString.substring(0, paddedPenceNumberString.length - 2):
38+
// Ignores the last 2 numbers in the string (these are pence) and defines the remaining numbers as pounds.
39+
// So if the number was 399 that would be £3. If th number was 2050 that would be £20
40+
// if it was 5p it would be 0
41+
42+
//5. const pence = paddedPenceNumberString.substring(paddedPenceNumberString.length - 2).padEnd(2, "0"):
43+
// takes the last 2 numbers of the string which represent the pence and if it is less than 2 digits adds trailing zeros to make it 2 digits long
44+
// due to step 3 the string should always have at least 3 numbers but this is a safety precaution
45+
46+
//6. console.log(`£${pounds}.${pence}`): prints the final result in the format of £pounds.pence to the console
47+
// prints the result £pounds.pence so in this case £3.99 it prints the £ sign then the value of pounds
48+
// designated by the $ sign and the value of pence designated by the $sign

0 commit comments

Comments
 (0)