Skip to content

Commit 5afd460

Browse files
committed
BMI calculation code
1 parent d6eb93e commit 5afd460

2 files changed

Lines changed: 35 additions & 9 deletions

File tree

‎Sprint-3/2-mandatory-debug/2.js‎

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,42 @@
22

33
// Predict the output of the following code:
44
// =============> Write your prediction here
5+
//getting the last digit of 103
6+
// const num = 103;
57

6-
const num = 103;
7-
8-
function getLastDigit() {
9-
return num.toString().slice(-1);
10-
}
8+
// function getLastDigit() {
9+
// return num.toString().slice(-1);
10+
// }
1111

12-
console.log(`The last digit of 42 is ${getLastDigit(42)}`);
13-
console.log(`The last digit of 105 is ${getLastDigit(105)}`);
14-
console.log(`The last digit of 806 is ${getLastDigit(806)}`);
12+
// console.log(`The last digit of 42 is ${getLastDigit(42)}`);
13+
// console.log(`The last digit of 105 is ${getLastDigit(105)}`);
14+
// console.log(`The last digit of 806 is ${getLastDigit(806)}`);
1515

1616
// Now run the code and compare the output to your prediction
1717
// =============> write the output here
18+
//-The last digit of 42 is 3
19+
//-The last digit of 105 is 3
20+
//-The last digit of 806 is 3
21+
1822
// Explain why the output is the way it is
23+
// -Every time the function calls 103
1924
// =============> write your explanation here
2025
// Finally, correct the code to fix the problem
2126
// =============> write your new code here
2227

2328
// This program should tell the user the last digit of each number.
2429
// Explain why getLastDigit is not working properly - correct the problem
30+
//The function was looking at the outside "num" but Now there are two (num) one outside the scope "const num= 103" and i added another inside the function scope.
31+
//The function calculates something and returns it then console.log outside receives that returned value and prints. it.
32+
const num = 103;
33+
34+
function getLastDigit() {
35+
return num.toString().slice(-1);
36+
37+
// console.log(getLastDigit(42));
38+
}
39+
console.log(`The last digit of 42 is ${getLastDigit(42)}`);
40+
console.log(`The last digit of 105 is ${getLastDigit(105)}`);
41+
console.log(`The last digit of 806 is ${getLastDigit(806)}`);
42+
43+

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

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

17+
1718
function calculateBMI(weight, height) {
18-
// return the BMI of someone based off their weight and height
19+
const bmi= weight / (height * height);
20+
return bmi.toFixed(1);
21+
22+
// return the BMI of someone based off their weight and height
1923
}
24+
25+
console.log(`Your BMI is ${calculateBMI(70, 1.73)}, based on your weight and height`);
26+

0 commit comments

Comments
 (0)