Skip to content

Commit 1472b08

Browse files
committed
refactored code
1 parent 2795463 commit 1472b08

1 file changed

Lines changed: 7 additions & 9 deletions

File tree

‎Sprint-3/3-mandatory-implement/3-to-pounds.js‎

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,18 @@
66
// You should call this function a number of times to check it works for different inputs
77

88
function toPounds(pence) {
9-
//Declare penceString variable
10-
let penceString = pence;
11-
// Store penceString value with pence on the end and make sure its at least 3 characters long add 0 at start if needed.
12-
let penceStringWithoutTrailingP = penceString
13-
.substring(0, penceString.length - 1)
9+
// Store pence value with pence on the end and make sure its at least 3 characters long add 0 at start if needed.
10+
const penceWithoutTrailingP = pence
11+
.substring(0, pence.length - 1)
1412
.padStart(3, "0");
1513
// copy everything apart from the last two characters
16-
let poundsResult = penceStringWithoutTrailingP.substring(
14+
const poundsResult = penceWithoutTrailingP.substring(
1715
0,
18-
penceStringWithoutTrailingP.length - 2,
16+
penceWithoutTrailingP.length - 2,
1917
);
2018
// start at the last two characters and take everything from there to end and make sure that value is two characters long add 0 if needed
21-
let penceResult = penceStringWithoutTrailingP
22-
.substring(penceStringWithoutTrailingP.length - 2)
19+
const penceResult = penceWithoutTrailingP
20+
.substring(penceWithoutTrailingP.length - 2)
2321
.padEnd(2, "0");
2422
// return result of poundResult and penceResult in a template string
2523
return `£${poundsResult}.${penceResult}`;

0 commit comments

Comments
 (0)