Skip to content

Commit 9781f22

Browse files
committed
explained step by step breakdown of each line
1 parent e556d1d commit 9781f22

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,20 @@ console.log(`£${pounds}.${pence}`);
2121
// The program then builds up a string representing the price in pounds
2222

2323
// You need to do a step-by-step breakdown of each line in this program
24+
2425
// Try and describe the purpose / rationale behind each step
2526

2627
// To begin, we can start with
2728
// 1. const penceString = "399p": initialises a string variable with the value "399p"
29+
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

Comments
 (0)