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
{{ message }}
Repository navigation
Commit 7da57e5
Browse filesBrowse the repository at this point in the historyBrowse files
// we are tillING IT TO start from the first inex (0) and not to include index 3 which penceString.length than use the operator - to subtract 1
38
-
// we intialise a string variable const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"); and assign its value to be
34
+
//const penceStringWithoutTrailingP: a string variable is initialised and assigned
35
+
// using the = operator to be equal to the value of string penceString when the method substring is used to cut part of the string
36
+
//so substring(0, penceString.length - 1);: means use substring method starting from index zero and end before the last character pencestring.length-1 : which is the length of the string
37
+
//but how dom we know which index? Its is basically the characters in string where "399p" means we have 4 characters and we want to take 1
38
+
//do 4 - 1 = 3 , so we are removing p character from the string so it becomes 399
39
+
//this line says take the string penceStringWithoutTrailingP and use padStart()string method
40
+
// (3, "0"); this means make the string 3 characters at least and if not add o to the beginning
// we assign the value to be starting with MINUMUM LENGTH IS 3 CHARACTERS than if not ADD THE VALUE 0 TO THE BEGINNING
45
-
// we initialise a variable const pounds and assign its value to be the value from using paddedPenceNumberString.substring
46
-
//paddedPenceNumberString.substring value is found by starting from the first index WITH LENGTH 3 and ending with paddedPenceNumberString.length subtracted by the operator 2
47
49
48
-
// IN THIS LINE const pence = paddedPenceNumberString
49
-
constpence=paddedPenceNumberString
50
-
.substring(paddedPenceNumberString.length-2)
51
-
.padEnd(2,"0");
52
-
53
-
console.log(`£${pounds}.${pence}`);
54
-
// we initialise a string variable and assign its value to be the paddedPenceNumberString variable with the value from using the substring method
55
-
// the substring method is calculated by using the length property or the value of paddedPenceNumberString subtracting it by 2 using operator -
56
-
// than using the method .padEnd to specify that if the length is not two add the value 0
57
-
// last we ask the console to print the values in pounds and pence
50
+
//this (paddedPenceNumberString.length - 2) mean find the position of the last 2 characters
51
+
//in the string paddedPenceNumberString
52
+
//substring()means take the last 2 characters you found from the string
53
+
//.padEnd(2, "0"); means if the result is less than two characters , than add zero at
54
+
//the end until it reaches two digits
55
+
//const pence = paddedPenceNumberString
56
+
//.substring(paddedPenceNumberString.length - 2)
57
+
// .padEnd(2, "0");
58
+
//this line uses console.log to print the value of ponds and pence
59
+
//it uses literal template to find the value of pounds, uses a decimal point , than finds the value of pence
0 commit comments