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
// which is "399". We got this value by the method substring(0, penceString.length - 1) called by penceString
32
+
// Breaking down the expression penceString.substring(0, penceString.length - 1)
33
+
// a) penceString.length - 1 this counts the number of characters in the penceString String and then subtracts 1 from it (4-1=3)
34
+
// then it will look like this penceString.substring(0, 3)
35
+
// b) penceString.substring(0, penceString.length - 1) then the substring method called by penceString
36
+
// is used produce a slice of small string from a big string
37
+
// it takes two arguments the first one tells where to start slicing and the second one tells where to stop
38
+
// (but the last character is not included)
39
+
// Therefore const penceStringWithoutTrailingP will be assigned "399"
40
+
41
+
// 3. In line 8 const paddedPenceNumberString is declared and it will hold the value of penceStringWithoutTrailingP.padStart(3, "0")
42
+
// which is still "399". In this expression we used the method padStart called by penceStringWithoutTrailingP and this method is basically
43
+
// adds characters at the start of our String. It takes two arguments the first one is telling how many characters we want in our String
44
+
// and second argument tells the character that needs to be added so that we get out desired number of characters in our String.
45
+
// since our String length is 3 the method will not do anything
46
+
47
+
// 4. From line 9 to line 12 const pounds is declared and it will hold the value of paddedPenceNumberString.substring(0, paddedPenceNumberString.length - 2,)
48
+
// which is "3". We got this value by the method substring(0, paddedPenceNumberString.length - 2,) called by paddedPenceNumberString
49
+
// Breaking down the expression paddedPenceNumberString.substring(0, paddedPenceNumberString.length - 2,)
50
+
// a) paddedPenceNumberString.length - 2 this counts the number of characters in the paddedPenceNumberString then subtracts 2 from it (3-2=1)
51
+
// then it will look like this paddedPenceNumberString.substring(0, 1)
52
+
// b) paddedPenceNumberString.substring(0, paddedPenceNumberString.length - 2,) then the substring method called by paddedPenceNumberString is used to
53
+
// produce a slice of small string from a big string
54
+
// it takes two arguments the first one tells where to start slicing and the second one tells where to stop
55
+
// (but the last character is not included)
56
+
// Therefore const pounds will assigned "3"
57
+
58
+
// 5. From line 14 to line 16 const pence is declared and it will hold the value of
59
+
// paddedPenceNumberString.substring(paddedPenceNumberString.length - 2).padEnd(2, "0") which is "99"
60
+
// Breaking down the expression
61
+
// a) paddedPenceNumberString.length - 2 this will count the number of characters in paddedPenceNumberString and then subtracts 2 from it (3-2=1)
62
+
// paddedPenceNumberString.substring(paddedPenceNumberString.length - 2) then this substring method will produce small string from it starting from index 1 which will be "99"
63
+
//then finally paddedPenceNumberString.substring(paddedPenceNumberString.length - 2).padEnd(2, "0") the padEnd method will add characters at the end of the String
64
+
// and will take two arguments first will tell how many characters we need in our string and the second will tell the character that needs to be added
65
+
// since our String length is 2 the method will do nothing
66
+
67
+
// 6. Finally line 18 will print out the desired format we have added what to be printed inside the back-ticks if they are variables we will put them in ${}
0 commit comments