Skip to content

Commit 5b94357

Browse files
added 3 mre problem solved result
1 parent 49eab14 commit 5b94357

File tree

3 files changed

+121
-0
lines changed

3 files changed

+121
-0
lines changed

B. Condition/bmi-calc.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/* problem-2
2+
3+
BMI Calculator and Health Category
4+
5+
Create a JavaScript program that calculates the Body Mass Index (BMI) and assigns a health category based on the BMI value. Use nested if-else statements to determine the health category.
6+
7+
- Calculate BMI using the formula: BMI = weight (kg) / (height (m))^2
8+
- BMI < 18.5, you are underweight.
9+
- BMI >= 18.5 and BMI <=24.9, you are normal.
10+
- BMI >=25 and BMI <= 29.9, you are overweight.
11+
- Otherwise, you are obese.
12+
13+
*/
14+
let weight = 60;
15+
let height = 1.5;
16+
let bmi = ((weight / (height * height)).toFixed(2));
17+
// console.log(bmi);
18+
if (bmi < 18.5) {
19+
console.log(" You are underweight");
20+
21+
}
22+
else {
23+
if (bmi >= 18.5 && bmi <= 24.9) {
24+
console.log("you are normal.");
25+
}
26+
else if (bmi >= 25 && bmi <= 29.9)
27+
console.log("you are overweight.");
28+
else {
29+
console.log("you are obese.");
30+
}
31+
}
32+
33+

B. Condition/drinks.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/* problem-1
2+
3+
Free Drinks
4+
- Burger more than 500tk: free Coke
5+
- Else Coke: 30tk
6+
*/
7+
let burgerPrice = 550;
8+
let coke = 30;
9+
if (burgerPrice > 500) {
10+
console.log("You Will able to get a free coke");
11+
}
12+
else {
13+
console.log("You have to buy coke");
14+
}

B. Condition/grade-calc.js

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/* problem-3
2+
3+
Grade Calculator
4+
5+
Create a simple JavaScript program that takes a student's score as input and returns their corresponding grade based on the following grading scale:
6+
7+
A+: 80-100
8+
A: 70-79
9+
B: 60-69
10+
C: 50-59
11+
D: 40-49
12+
E: 33-39
13+
F: 0-32
14+
15+
*/
16+
let marks = 100;
17+
// normal solution
18+
if (marks >= 80 && marks <= 100) {
19+
console.log("You Got A+");
20+
}
21+
else if (marks >= 70 && marks <= 79) {
22+
console.log("You Got A");
23+
}
24+
else if (marks >= 60 && marks <= 69) {
25+
console.log("You Got B");
26+
}
27+
else if (marks >= 50 && marks <= 59) {
28+
console.log("You Got C");
29+
}
30+
else if (marks >= 40 && marks <= 49) {
31+
console.log("You Got D");
32+
}
33+
else if (marks >= 33 && marks <= 39) {
34+
console.log("You Got E");
35+
}
36+
else if (marks > 100) {
37+
console.log("Invalid Marks");
38+
}
39+
else {
40+
console.log("You Have Failed in the Exam");
41+
}
42+
43+
44+
// solution by Nested
45+
if (marks >= 80 && marks <= 100) {
46+
console.log("You Got A+");
47+
}
48+
else {
49+
if (marks >= 70 && marks <= 79) {
50+
console.log("You Got A");
51+
}
52+
else if (marks >= 60 && marks <= 69) {
53+
console.log("You Got B");
54+
}
55+
else if (marks >= 50 && marks <= 59) {
56+
console.log("You Got C");
57+
}
58+
else if (marks >= 40 && marks <= 49) {
59+
console.log("You Got D");
60+
}
61+
else if (marks >= 33 && marks <= 39) {
62+
console.log("You Got E");
63+
}
64+
else if (marks > 100) {
65+
console.log("Invalid Marks");
66+
}
67+
else {
68+
console.log("You Have Failed in the Exam");
69+
}
70+
71+
}
72+
// ternary solution
73+
let result = marks >= 80 && marks <= 100 ? "You Got A+" : marks >= 70 && marks <= 79 ? "You Got A" : marks >= 60 && marks <= 69 ? "You Got B" : marks >= 50 && marks <= 59 ? "You Got C" : marks >= 40 && marks <= 49 ? "You Got D" : marks >= 33 && marks <= 39 ? "You Got E" : marks > 100 ? "Invalid Marks" : "You Have Failed in the Exam";
74+
console.log(result);

0 commit comments

Comments
 (0)