Skip to content

Commit 17a2243

Browse files
committed
Complete all mandatory-implement exercises
1 parent 39a813f commit 17a2243

3 files changed

Lines changed: 33 additions & 0 deletions

File tree

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,9 @@
1515
// It should return a string of their Body Mass Index to 1 decimal place
1616

1717
function calculateBMI(weight, height) {
18+
let bmi = weight / (height * height);
19+
return bmi.toFixed(1);
20+
1821
// return the BMI of someone based off their weight and height
1922
}
23+
console.log(`Your Bmi is ${calculateBMI(56, 1.66)}`);

‎Sprint-3/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 upperCaseMaker(str) {
19+
let upperCased = str.toUpperCase();
20+
let symbol = "_";
21+
let underscored = upperCased.split(" ").join(symbol);
22+
return underscored;
23+
}
24+
25+
console.log(upperCaseMaker("the sun is shining"));

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,23 @@
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+
const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0");
14+
const pounds = paddedPenceNumberString.substring(
15+
0,
16+
paddedPenceNumberString.length - 2,
17+
);
18+
const pence = paddedPenceNumberString
19+
.substring(paddedPenceNumberString.length - 2)
20+
.padEnd(2, "0");
21+
22+
return `£${pounds}.${pence}`;
23+
}
24+
25+
console.log(toPounds("11000p"));
26+
// results of some different inputs: 0p -> £0.00, 3p -> £0.03, 50p -> £0.50, 170p -> £1.70, 1200p -> £12.00, 11000p -> £110.00

0 commit comments

Comments
 (0)