Skip to content

Commit c45239d

Browse files
committed
completed tasks in Sprint-1/2-mandatory-interpret/3-to-pounds.js
1 parent cce5a1c commit c45239d

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const penceString = "399p";
1+
const penceString = "4354301p";
22

33
const penceStringWithoutTrailingP = penceString.substring(
44
0,
@@ -24,4 +24,15 @@ console.log(`£${pounds}.${pence}`);
2424
// Try and describe the purpose / rationale behind each step
2525

2626
// To begin, we can start with
27+
2728
// 1. const penceString = "399p": initialises a string variable with the value "399p"
29+
30+
//2. const penceStringWithoutTrailingP = penceString.substring(0,penceString.length-1) initialises a string variable that has a value of penceString without the last character
31+
32+
//3. const paddedPenceString = pence~StringWithourTrailingP.padStart(3,'0') initialises a string variable that has the value of penceStringWithoutTrailingP but ensures the string is at least 3 characters long by adding 0's to the start if needed
33+
34+
//4. const pounds = paddedPenceNumberString.substring(0, paddedPenceNumberString.length - 2) initialises a string variable that has the value of paddedPenceNumberString without the last 2 characters
35+
36+
//5. const pence = paddedPenceNumberString.subString(paddedPenceNumberString.length-2).padEnd(2,'0') initialises a string variale with the value of the last 2 characters of paddedPenceNumberString and ensures the string is at least 2 characters long by adding 0's to the end if needed
37+
38+
//6. console.log(`£${pounds}.${pence}`) prints out the value of pounds and pence in £pounds.pence format by using string interpolation

0 commit comments

Comments
 (0)