Skip to content

Commit 82a1922

Browse files
committed
Merge branch 'coursework/sprint-2' of https://github.com/leigh-ross/Module-JavaScript-Fundamentals into coursework/sprint-2
"Trying to fix my commits"
2 parents 656d965 + e339abe commit 82a1922

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,10 @@ 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+
// 2. const penceStringWithoutTrailingP: from index 0, to length of string - 1 (4-1=3). (0,3) we get the string from index 0 to index 2 which removes the p at the end.
29+
// 3. const paddedPenceNumberString: if length < 3, pad start of string with "0". since it is we just get 399.
30+
// 4. const pounds: take string from index 0 to length of string - 2 (3-2=1). (0,1) we get the 1st index "3".
31+
// 5. .substring(): length = 3. (3-2=1). (1,end of string). this gives us 99
32+
// 6. .padEnd(): if previous length of string < 2: pad end with "0"
33+
// 7. console.log() basically just prints pounds and pence as the proper format (£"pound"."pence") using string literals
34+
// NB: padding is for a safety measure if the inputs were shorter.

0 commit comments

Comments
 (0)