Skip to content

Commit 89e21be

Browse files
committed
Solve the last task in madatory-interpret with my own words
1 parent 8fd0318 commit 89e21be

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,26 @@
11
const penceString = "399p";
2+
//initialises a string variable with the value "399p"
23

34
const penceStringWithoutTrailingP = penceString.substring(
45
0,
56
penceString.length - 1
67
);
8+
// declare a new var and assign penceString value without last character (p)/
79

810
const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0");
11+
//declare a new variable and Make sure it is at least 3 digits long eg: 1 become 001.
12+
913
const pounds = paddedPenceNumberString.substring(
1014
0,
1115
paddedPenceNumberString.length - 2
1216
);
17+
//declare a new variable and assign the paddedPenceNumberString value without last two digit.
1318

1419
const pence = paddedPenceNumberString
1520
.substring(paddedPenceNumberString.length - 2)
1621
.padEnd(2, "0");
17-
22+
// pence= take the pound length and remove it and keep all rest digit and if the shorter than 2 digit add 0 until paddedPenceNumberString
23+
// .substring(paddedPenceNumberString.length - 2) becomes 2 digits
1824
console.log(${pounds}.${pence}`);
1925

2026
// This program takes a string representing a price in pence

0 commit comments

Comments
 (0)