Skip to content

Commit 4a7731e

Browse files
committed
3-interpret done
1 parent 6cd17cc commit 4a7731e

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
11
const penceString = "399p";
2-
2+
// 1. const penceString = "399p": initialises a string variable with the value "399p"
33
const penceStringWithoutTrailingP = penceString.substring(
44
0,
55
penceString.length - 1
66
);
7-
7+
//2. removes "P" from the string
88
const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0");
9+
//3. Ensures the string is at least 3 characters long by adding 0 to the start
910
const pounds = paddedPenceNumberString.substring(
1011
0,
1112
paddedPenceNumberString.length - 2
1213
);
13-
14+
//4. Extracts everything except the last 2 digits of paddedPenceNumberString
1415
const pence = paddedPenceNumberString
1516
.substring(paddedPenceNumberString.length - 2)
1617
.padEnd(2, "0");
17-
18+
//5. takes the last 2 digits as the pence from paddedPenceNumberString
1819
console.log(${pounds}.${pence}`);
20+
//6. Prints the formatted pounds-and-pence value
1921

2022
// This program takes a string representing a price in pence
2123
// The program then builds up a string representing the price in pounds

0 commit comments

Comments
 (0)