Skip to content

Commit 99dee79

Browse files
committed
Merge branch 'Sprint-2/3-mandatory-implement' into Sprint-2/1-key-errors
2 parents 19aa42e + ee22da6 commit 99dee79

File tree

3 files changed

+48
-1
lines changed

3 files changed

+48
-1
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,7 @@
1616

1717
function calculateBMI(weight, height) {
1818
// return the BMI of someone based off their weight and height
19-
}
19+
const bmi = weight / (height * height);
20+
return bmi.toFixed(1);
21+
}
22+
console.log(calculateBMI(70, 1.73)); // should return 23.4

Sprint-2/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+
function toUpperSnakeCase(str) {
19+
// convert the string to UPPER_SNAKE_CASE
20+
return str.toUpperCase().replaceAll(" ", "_");
21+
}
22+
console.log(toUpperSnakeCase("hello there"));
23+
console.log(toUpperSnakeCase("lord of the rings"));

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

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,40 @@
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+
// const penceString = "399p";
8+
9+
// const penceStringWithoutTrailingP = penceString.substring(
10+
// 0,
11+
// penceString.length - 1
12+
// );
13+
14+
// const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0");
15+
// const pounds = paddedPenceNumberString.substring(
16+
// 0,
17+
// paddedPenceNumberString.length - 2
18+
// );
19+
20+
// const pence = paddedPenceNumberString
21+
// .substring(paddedPenceNumberString.length - 2)
22+
// .padEnd(2, "0");
23+
24+
25+
function toPounds (penceString) {
26+
const penceStringWithoutTrailingP = penceString.substring(0, penceString.length - 1);
27+
const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0");
28+
const pounds = paddedPenceNumberString.substring(0, paddedPenceNumberString.length - 2);
29+
const pence = paddedPenceNumberString
30+
.substring(paddedPenceNumberString.length - 2)
31+
.padEnd(2, "0");
32+
return ${pounds}.${pence}`;
33+
}
34+
console.log(toPounds("399p"));
35+
36+
// This program takes a string representing a price in pence
37+
// The program then builds up a string representing the price in pounds
38+
39+
// You need to do a step-by-step breakdown of each line in this program
40+
// Try and describe the purpose / rationale behind each step
41+
42+
// To begin, we can start with
43+
// 1. const penceString = "399p": initialises a string variable with the value "399p"

0 commit comments

Comments
 (0)