Skip to content

Commit c9730ff

Browse files
committed
sprint 3 ex 1-3 solutions
1 parent 83072ae commit c9730ff

3 files changed

Lines changed: 36 additions & 0 deletions

File tree

‎Sprint-3/3-mandatory-implement/1-bmi.js‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,10 @@
1717
function calculateBMI(weight, height) {
1818
// return the BMI of someone based off their weight and height
1919
}
20+
21+
function calculateBMI(weight, height) {
22+
const bmi = weight / (height * height);
23+
return bmi.toFixed(1);
24+
}
25+
26+
console.log(calculateBMI(70, 1.73)); // "23.4"

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,11 @@
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+
return str.toUpperCase().replaceAll(" ", "_");
20+
}
21+
22+
console.log(toUpperSnakeCase("hello there")); // "HELLO_THERE"
23+
console.log(toUpperSnakeCase("lord of the rings")); // "LORD_OF_THE_RINGS"
24+

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,24 @@
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+
const penceStringWithoutTrailingP = penceString.substring(
10+
0,
11+
penceString.length - 1
12+
);
13+
14+
const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0");
15+
16+
const pounds = paddedPenceNumberString.substring(
17+
0,
18+
paddedPenceNumberString.length - 2
19+
);
20+
21+
const pence = paddedPenceNumberString
22+
.substring(paddedPenceNumberString.length - 2)
23+
.padEnd(2, "0");
24+
25+
return `£${pounds}.${pence}`;
26+
}
27+

0 commit comments

Comments
 (0)