Skip to content

Commit 4aa0e25

Browse files
committed
3-to-pounds
1 parent 276f457 commit 4aa0e25

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

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

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,34 @@ 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: In line 1, a variable "penceString" was created holding the value "399p"
30+
// In line 3-6, Another variable "penceStringWithoutTrailingP" was created to remove the trainling "p".
31+
// That is, taking off the "p" in '399p' leaving it at just "399".
32+
33+
// Line 3-6 used the function substring(0, penceString.lrength - 1) to cut out the "p" in the "penceString" variable.
34+
// By starting count fron 0 (beginnning) of "399p".
35+
// "Using penceString.lenght - 1" to check the length of the value in the variable penceString = "399p" (4),
36+
// And deducting 1 from the value (399p - 1) leaving the value at "399"
37+
38+
// Line 8 a variable "paddedPenceNumberString" was created and a function padStart(3, "0")
39+
// was used to ensure the value of the variable remains at 3 and to be filled with "0" at the beginning if the value is less 3
40+
41+
// Line 9-12 created a variable "pounds" and used the subString(0, paddedPenceNumberString.length - 2 )
42+
// to start count from 0 of the "penceStringWithoutTrailingP" value which is 399.
43+
// It further removed the last two number in the value by checking the length of the value with "paddedPenceNumberString.length"
44+
// And subtracting 2 (399 - 2), cutting out 99 and leaving the value to remain 3.
45+
46+
// Line 14-16 created a variable "pence", using the subString(paddedPenceNumberString.length - 2)
47+
// to check the length of the value of the variable "paddedPenceNumberString" which remain 399 from line 8
48+
// The "substring(paddedPenceNumberString.length - 2)" function deducts 3 leaving the last two numbers 99
49+
// PadEnd(2, "0") ensure the value remains 2 and 0 to be added to value less than 2.
50+
// However, we already have in our "pence" variable at a value of 2 numbers "99"
51+
52+
// Line 18 printed our codes a formatted style adding the pound sign "£"
53+
54+
55+
56+
57+
58+

0 commit comments

Comments
 (0)