Skip to content

Commit d17370a

Browse files
commented what each line of code is doing
1 parent 198da68 commit d17370a

File tree

1 file changed

+27
-4
lines changed

1 file changed

+27
-4
lines changed

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

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,40 @@ const pounds = paddedPenceNumberString.substring(
1111
paddedPenceNumberString.length - 2
1212
);
1313

14-
const pence = paddedPenceNumberString
15-
.substring(paddedPenceNumberString.length - 2)
16-
.padEnd(2, "0");
14+
const pence = paddedPenceNumberString.substring(paddedPenceNumberString.length - 2).padEnd(2, "0");
1715

1816
console.log(${pounds}.${pence}`);
1917

18+
19+
2020
// This program takes a string representing a price in pence
2121
// The program then builds up a string representing the price in pounds
2222

2323
// You need to do a step-by-step breakdown of each line in this program
2424
// Try and describe the purpose / rationale behind each step
2525

2626
// To begin, we can start with
27-
// 1. const penceString = "399p": initialises a string variable with the value "399p"
27+
// 1. const penceString = "399p": initializes a string variable with the value "399p"
28+
29+
//2. const penceStringWithoutTrailingP = penceString.substring(
30+
// 0,
31+
// penceString.length - 1
32+
// );
33+
//initializes a string variable with the value "399" by removing the last character "p" from penceString
34+
35+
//3. const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0");
36+
//initializes a string variable with the value penceStringWithoutTrailingP, with a minimum length of 3 characters, if it happens to be shorter it will add a "0" at the beginning of the string for every character that is short
37+
38+
//4. const pounds = paddedPenceNumberString.substring(
39+
// 0,
40+
// paddedPenceNumberString.length - 2
41+
// );
42+
//initializes a string variable with the value of paddedPenceNumberString except the final 2 characters, thus extracting the pounds, in this case "3"
43+
44+
//5. const pence = paddedPenceNumberString
45+
// .substring(paddedPenceNumberString.length - 2)
46+
// .padEnd(2, "0")
47+
//it extracts the last two characters (pence) from paddedPenceNumberString and it makes sure that there's always gonna be two by adding "0" at the end
48+
49+
//6. console.log(`£${pounds}.${pence}`);
50+
//it logs £3.99

0 commit comments

Comments
 (0)