You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Sprint-2/3-mandatory-interpret/3-to-pounds.js
+7Lines changed: 7 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -1,20 +1,27 @@
1
+
//declaring a variable with the value of "399p"
1
2
constpenceString="399p";
2
3
4
+
//the .substring is removing the "p" from the value of penceString by taking the total length of the subString "4" - 1 = 3, by stripping the "p" leaving only 399
//The .substring is removing the "99" from the value of .penceStringWithoutTrailingP by taking the total length of the .penceStringWithoutTrailingP "3" - 2 = 1 by stripping the "99" leaving only the 3
9
14
constpounds=paddedPenceNumberString.substring(
10
15
0,
11
16
paddedPenceNumberString.length-2
12
17
);
13
18
19
+
// the .substring is doing the same as the "pound" variable declared in now line 14, by grabbing the last 2 characters "99" except it is ending the pad as safeguard to always ensure that two digits remain
14
20
constpence=paddedPenceNumberString
15
21
.substring(paddedPenceNumberString.length-2)
16
22
.padEnd(2,"0");
17
23
24
+
// console.log is using template literals to combine the currency symbol, pound string decimal point and pence string. Giving us an output of £3.99
18
25
console.log(`£${pounds}.${pence}`);
19
26
20
27
// This program takes a string representing a price in pence
0 commit comments