Skip to content

Commit 6db1797

Browse files
completed the mandatory implement file
1 parent 2008962 commit 6db1797

3 files changed

Lines changed: 36 additions & 4 deletions

File tree

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,20 @@
66

77
// squaring your height: 1.73 x 1.73 = 2.99
88
// dividing 70 by 2.99 = 23.41
9-
// Your result will be displayed to 1 decimal place, for example '23.4'.
9+
// Your result will be displayed to 1 decimal place, for example 23.4.
1010

1111
// You will need to implement a function that calculates the BMI of someone based off their weight and height
1212

1313
// Given someone's weight in kg and height in metres
1414
// Then when we call this function with the weight and height
15-
// It should return a string of their Body Mass Index to 1 decimal place
15+
// It should return their Body Mass Index to 1 decimal place
1616

1717
function calculateBMI(weight, height) {
18-
// return the BMI of someone based off their weight and height
18+
let result = (weight/(height*height));
19+
return Number(result.toFixed(1));
20+
21+
1922
}
23+
24+
console.log(calculateBMI(70,1.7))
25+
console.log(calculateBMI(72,1.7))

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,8 @@
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+
function toUpperSnakeCase(string) {
18+
return string.toUpperCase().replaceAll(" ", "_");
19+
}
20+
console.log(toUpperSnakeCase("hello there"));
21+
console.log(toUpperSnakeCase("lord of the rings"));
Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,27 @@
1-
// In Sprint-1, there is a program written in 3-mandatory-interpret/3-to-pounds.js
1+
// In Sprint-1, there is a program written in interpret/to-pounds.js
22

33
// You will need to take this code and turn it into a reusable block of code.
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+
function toPounds(penceString){
8+
const penceStringWithoutTrailingP = penceString.substring(
9+
0,
10+
penceString.length - 1
11+
);
12+
const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0");
13+
const pounds = paddedPenceNumberString.substring(
14+
0,
15+
paddedPenceNumberString.length - 2
16+
);
17+
18+
const pence = paddedPenceNumberString
19+
.substring(paddedPenceNumberString.length - 2)
20+
.padEnd(2, "0");
21+
return ${pounds}.${pence}`
22+
}
23+
24+
25+
console.log(toPounds('987p'));
26+
console.log(toPounds('909p'));
27+
console.log(toPounds('345p'));

0 commit comments

Comments
 (0)