Skip to content

Commit 1de4780

Browse files
committed
Answered questions
1 parent 6d1fdd2 commit 1de4780

1 file changed

Lines changed: 28 additions & 2 deletions

File tree

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

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ const penceString = "399p";
22

33
const penceStringWithoutTrailingP = penceString.substring(
44
0,
5-
penceString.length - 1
5+
penceString.length - 1,
66
);
77

88
const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0");
99
const pounds = paddedPenceNumberString.substring(
1010
0,
11-
paddedPenceNumberString.length - 2
11+
paddedPenceNumberString.length - 2,
1212
);
1313

1414
const pence = paddedPenceNumberString
@@ -25,3 +25,29 @@ 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(
30+
// 0,
31+
// penceString.length - 1
32+
//);
33+
// finds a substring starting at 0 index to 1 before the last index, and assigns the
34+
// substring to penceStringWithoutTrailingP. This removes the p and leaves us with just
35+
// the number
36+
37+
// 3. const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0");
38+
// Makes it so that the string is always at least 3 characters, by adding leading 0 until
39+
// it is 3 characters long.
40+
41+
// 4. const pounds = paddedPenceNumberString.substring(
42+
// 0,
43+
// paddedPenceNumberString.length - 2,
44+
//);
45+
// Finds the substring of number paddedPenceNumberString, with the last 2 digits cut off
46+
// basically finds the number of pounds by cutting off the pence
47+
48+
// 5. const pence = paddedPenceNumberString
49+
// .substring(paddedPenceNumberString.length - 2)
50+
// .padEnd(2, "0");
51+
// Takes the substring starting at the total length-2, to the end. Essentially taking the
52+
// last 2 digits
53+
// Then adds 0 to the beginning so it is at least 2 characters long

0 commit comments

Comments
 (0)