Skip to content

Commit 29c88fd

Browse files
committed
3-mandatory-implement sprint3 completed
1 parent c0d3b07 commit 29c88fd

2 files changed

Lines changed: 50 additions & 0 deletions

File tree

‎Sprint-3/3-mandatory-implement/2-cases.js‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,10 @@
1414
// You will need to come up with an appropriate name for the function
1515
// Use the MDN string documentation to help you find a solution
1616
// This might help https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toUpperCase
17+
18+
const str= "hello there"
19+
20+
function strToUpperCase(str) {
21+
return str.toUpperCase().replaceAll(" ","_")
22+
}
23+
console.log(strToUpperCase("lord of the rings"));

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

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,46 @@
44
// You will need to declare a function called toPounds with an appropriately named parameter.
55

66
// You should call this function a number of times to check it works for different inputs
7+
8+
// In Sprint-1, there is a program written in 3-mandatory-interpret/3-to-pounds.js
9+
10+
// You will need to take this code and turn it into a reusable block of code.
11+
// You will need to declare a function called toPounds with an appropriately named parameter.
12+
13+
// You should call this function a number of times to check it works for different inputs
14+
15+
16+
/*
17+
const penceString = "399p";
18+
19+
const penceStringWithoutTrailingP = penceString.substring(
20+
0,
21+
penceString.length - 1
22+
);
23+
24+
const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0");
25+
const pounds = paddedPenceNumberString.substring(
26+
0,
27+
paddedPenceNumberString.length - 2
28+
);
29+
30+
const pence = paddedPenceNumberString
31+
.substring(paddedPenceNumberString.length - 2)
32+
.padEnd(2, "0");
33+
34+
console.log(`£${pounds}.${pence}`);
35+
*/
36+
37+
function toPounds(penceString) {
38+
let noP = penceString.substring(0,penceString.length -1)
39+
let paddedP = noP.padStart(3,"0")
40+
let pounds= paddedP.substring(0, paddedP.length -2)
41+
42+
let pence= paddedP.substring(paddedP.length -2).padEnd(2,"0")
43+
44+
return `£${pounds}.${pence}`
45+
}
46+
console.log(toPounds("399p"))
47+
console.log(toPounds("5p"))
48+
console.log(toPounds("52p"))
49+
console.log(toPounds("1244p"))

0 commit comments

Comments
 (0)