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
// 1. const penceString = "399p": initialises a string variable with the value "399p"
27
+
// 2.
28
+
// 3. const penceStringWithoutTrailingP = penceString.substring( : declares new var and assigns the pence string excluding trailing p
29
+
// 4. 0, : first value of the function, this is to tell the function to start from the first charachtar in the string
30
+
// 5. penceString.length - 1 : second value of the funtion, it takes the string lengs mines 1 (to exclude trailing p)
31
+
// 6. ); : closed th funtion.
32
+
// 7. const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"); : it padds the number with 0 from the start (to make number readable and clear)
33
+
// 8. const pounds = paddedPenceNumberString.substring( : declares new variable to store pounds, it takes the last two numbers from the number and stores everything that is before the last two numbers because they are pence not pounds.
34
+
// 9. 0, : set 0 to start from the first character.
35
+
// 10. paddedPenceNumberString.length - 2 : here is where it excludes the last two numbers (the pence).
36
+
// 11. ); : closes function.
37
+
// 12.
38
+
// 13. const pence = paddedPenceNumberString : declares new var to store pence
39
+
// 14. .substring(paddedPenceNumberString.length - 2) : identifies the last two numbers (pence) and stores them.
40
+
// 15. .padEnd(2, "0"); : to pad the pence with 0 from the end
41
+
// 16.
42
+
// 17. console.log(`£${pounds}.${pence}`); : to write the result, it prints the two variables, pounds and pence. it adds £ to show that it's pound.
0 commit comments