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
//const penceString = "399p"; creates a variable. This string represents a price in pence.
30
+
//We then count the variable penceString using index starting from 0 and ending at 3.
31
+
//.length tells us how many characters there are in a string which in this case its 4.
32
+
//Because we know penceString = 4 we have to then subtract 4-1=3.---> we have penceString.length-1 which then becomes 4 - 1 = 3.
33
+
//we are doing this so we can remove the final character.
34
+
//penceString.substring(0, 3) will give us "399"
35
+
//padStart() adds characters to the beginning of a string until it reaches a certain length, we asked for a length of 3.
36
+
//The final two characters represents pence and we are trying to get poundsright now.Because we have "399" and the last two digits represents pence and the character before that represents pounds.
37
+
//we are subtracting 2 because when using substringwe remove the part that belongs to pence, 3 | 99
38
+
//padEnd count at the position of the last two digits and take everything after that so we can get the right value for pence.
39
+
//here we are making sure that pence has 2 characters- this generally means that if the string does not add to 2 characters, add 0 to the end until its 2 characters Long
40
+
//console.log displays something in the console as the backticks create a template literal inside it we put our variables.
0 commit comments