Skip to content

Commit c810489

Browse files
committed
mandatory-implement task are done
1 parent fda7742 commit c810489

File tree

3 files changed

+45
-2
lines changed

3 files changed

+45
-2
lines changed

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@
1414
// Then when we call this function with the weight and height
1515
// It should return their Body Mass Index to 1 decimal place
1616

17+
// Function to calculate BMI
1718
function calculateBMI(weight, height) {
18-
// return the BMI of someone based off their weight and height
19-
}
19+
// return the BMI of someone based off their weight and height
20+
// Step 1: divide weight by height squared
21+
// Step 2: round the result to 1 decimal place
22+
return (weight / (height * height)).toFixed(1);
23+
}
24+
25+
console.log(calculateBMI(70, 1.73));

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,19 @@
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 to convert a string to UPPER_SNAKE_CASE
19+
function toUpperSnakeCase(str) {
20+
// Step 1: convert the string to uppercase
21+
let upperStr = str.toUpperCase();
22+
23+
// Step 2: replace spaces with underscores
24+
let snakeCaseStr = upperStr.replace(/ /g, "_");
25+
26+
// Step 3: return the result
27+
return snakeCaseStr;
28+
}
29+
30+
console.log(toUpperSnakeCase("hello there"));
31+
console.log(toUpperSnakeCase("lord of the rings"));
32+
console.log(toUpperSnakeCase("javascript is fun"));

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+
8+
// Function to convert pence to pounds
9+
function toPounds(penceString) {
10+
// Step 1: remove the "p" at the end
11+
let numberString = penceString.slice(0, -1);
12+
13+
// Step 2: make sure it has at least 3 digits by adding zeros at the start
14+
numberString = numberString.padStart(3, "0");
15+
16+
// Step 3: split into pounds and pence
17+
let pounds = numberString.slice(0, -2);
18+
let pence = numberString.slice(-2);
19+
20+
// Step 4: return formatted string
21+
return "£" + pounds + "." + pence;
22+
}
23+
24+
console.log(toPounds("399p"));
25+
console.log(toPounds("50p"));
26+
console.log(toPounds("5p"));
27+
console.log(toPounds("1200p"));

0 commit comments

Comments
 (0)