Skip to content

Commit 09b1e52

Browse files
committed
3-to-pounds.js
1 parent fe53ddf commit 09b1e52

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,12 @@
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+
function toUpperSnakeCase(str) {
19+
// Replace spaces with underscores and convert to uppercase
20+
return str.replace(/ /g, "_").toUpperCase();
21+
}
22+
23+
24+
console.log(toUpperSnakeCase("hello there")); // "HELLO_THERE"
25+
console.log(toUpperSnakeCase("lord of the rings")); // "LORD_OF_THE_RINGS"

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,20 @@
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+
function toPounds(penceString) {
9+
// Remove trailing 'p' and pad with zeros to ensure at least 3 digits
10+
const pence = penceString.substring(0, penceString.length - 1).padStart(3, "0");
11+
// Get pounds and pence parts
12+
const pounds = pence.substring(0, pence.length - 2);
13+
const pencePart = pence.substring(pence.length - 2).padEnd(2, "0");
14+
// Return formatted string
15+
return ${pounds}.${pencePart}`;
16+
}
17+
18+
19+
console.log(toPounds("399p")); // £3.99
20+
console.log(toPounds("9p")); // £0.09
21+
console.log(toPounds("99p")); // £0.99
22+
console.log(toPounds("100p")); // £1.00
23+
console.log(toPounds("1234p")); // £12.34

0 commit comments

Comments
 (0)