Skip to content

Commit af468ca

Browse files
committed
interpret exercise 3
1 parent 7fcde6c commit af468ca

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

‎Sprint-2/3-mandatory-interpret/3-to-pounds.js‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,15 @@ console.log(`£${pounds}.${pence}`);
2525

2626
// To begin, we can start with
2727
// 1. const penceString = "399p": initialises a string variable with the value "399p"
28+
29+
// Line 3 to 6: declaring a new variable called penceSrtingWithoutTraiingP, then uses the .substring method to select indexes from 0, to penceString variable.length which gives us all 4 indexes. Then -1 to remove the p.
30+
31+
// Line 8: declare new variable, paddedPenceNumberString, which equates to penceStringWithoutTrailingP then using the .padStart method to specify string length and pad it if it is short of that length. it specifies target length as 3 and padding character as 0.
32+
33+
// Line 9 to 12: New variable declared called pounds, equates to paddedPenceNumberString then accessing substring method to create a new substring, from index 0 to length of paddedPenceNumberString which is 3 then -2 which makes it 1, which is the first index in the string: "3".
34+
35+
// Line 14 to 16: New variable declared called pence, equates to paddedPenceNumberString. The .substring method is used to create a new string, which is paddedPenceNumberString.length which is 3, the -2 which is 1.
36+
// because only one index is called, that being 1, the second index, this means that 1 and everything after it is included.
37+
// Then .padEnd method is used, which is the opposite of padStart, it pads the ending of the index in the case of string length being short of specified length. 2 is the length and 0 is the padding character, which is not needed in this case because string meets length.
38+
39+
//Line 18: console.log to see the result in terminal while using template lateral to include multiple variables.

0 commit comments

Comments
 (0)