Skip to content

Commit d424070

Browse files
solved the 3-mandatory implement file
1 parent 14fee9a commit d424070

File tree

3 files changed

+31
-3
lines changed

3 files changed

+31
-3
lines changed

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@
1515
// It should return their Body Mass Index to 1 decimal place
1616

1717
function calculateBMI(weight, height) {
18-
let result = weight / (height*height);
18+
let result = Number(weight/(height*height));
1919
return result.toFixed(1);
2020

21-
// return the BMI of someone based off their weight and height
21+
2222
}
2323

24-
console.log(calculateBMI(70,168))
24+
console.log(calculateBMI(70,1.7))
25+
console.log(calculateBMI(72,1.7))

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,9 @@
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 toUpperSnakeFormat(string){
18+
return string.toUpperCase().replaceAll(" ","_")
19+
20+
}
21+
console.log(toUpperSnakeFormat("hello there"))
22+
console.log(toUpperSnakeFormat("lord of the rings"))

Sprint-2/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+
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)