Skip to content

Commit ed06b15

Browse files
committed
pound.js file update
1 parent 996180e commit ed06b15

1 file changed

Lines changed: 27 additions & 7 deletions

File tree

Sprint-1/3-mandatory-interpret/3-to-pounds.js

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,44 @@ const penceStringWithoutTrailingP = penceString.substring(
44
0,
55
penceString.length - 1
66
);
7+
// console.log(penceStringWithoutTrailingP);
78

89
const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0");
10+
// console.log(paddedPenceNumberString);
911
const pounds = paddedPenceNumberString.substring(
1012
0,
1113
paddedPenceNumberString.length - 2
1214
);
15+
// console.log(pounds)
1316

1417
const pence = paddedPenceNumberString
1518
.substring(paddedPenceNumberString.length - 2)
1619
.padEnd(2, "0");
17-
20+
// console.log(pence)
1821
console.log(${pounds}.${pence}`);
1922

20-
// This program takes a string representing a price in pence
21-
// The program then builds up a string representing the price in pounds
23+
// 1. const penceString = "399p": initialises a string variable with the value "399p"
24+
// 2. const penceStringWithoutTrailingP = penceString.substring(0, penceString.length-1): this
25+
// variable creates a new string that cuts the penceSting to 399,so it basically creates a new
26+
// string from index 0, and removes the last index
27+
// 3. const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"); this variable sets
28+
// the penceStringWithoutTrailingP string length to 3, and if the length is shorter than 3 it adds
29+
// "0" in front.
30+
// 4. const pounds = paddedPenceNumberString.substring(0,paddedPenceNumberString.length - 2)
31+
// this variable uses the subString function to further slice the paddedPenceNumberString
32+
// string on from the first index and remove the last 2 parts of in. In this case the string goes
33+
// from '399' to just '3'
34+
35+
// 5.const pence = paddedPenceNumberString.substring(paddedPenceNumberString.length - 2).padEnd(2, "0");
36+
// this variable creates a new string from the paddedPenceNumberString variable using the subString
37+
// function. This time it creates a new string from the last 2 indexes. Furthermore it sets the target
38+
// length for this new variable to 2 and if is is less than 2 it sets a condition to add
39+
// a "0" in front
40+
41+
42+
//6. console.log(`£${pounds}.${pence}`); this is a function call that displays the final amount in
43+
// pounds. It uses string interpolation to directly use the variable values pound and pence and also
44+
// formats the string by adding £ before the values. So the output displayed will be £3.99
45+
2246

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

26-
// To begin, we can start with
27-
// 1. const penceString = "399p": initialises a string variable with the value "399p"

0 commit comments

Comments
 (0)