THAPA TECHNICAL

HOUSE OF WEB DEVELOPERS AND TECHNOLOGY.

Modern JavaScript Advanced BMI Calculator Challenge

Modern JavaScript Advanced BMI Calculator Challenge using Objects & Methods





Welcome, to Modern JavaScript Advanced BMI Calculator Challenge using Objects & Methods in Hindi.

BMI Calculator: https://youtu.be/OU1INv5o7sE
Follow me Insta: https://www.instagram.com/vinodthapa55/
JavaScript Object Tutorial: https://youtu.be/mXZz0SHl7dI

JavaScript is designed on a simple object-based paradigm. An object is a collection of properties, and a property is an association between a name (or key) and a value. A property's value can be a function, in which case the property is known as a method.

JavaScript is designed on a simple object-based paradigm. An object is a collection of properties, and a property is an association between a name (or key) and a value. A property's value can be a function, in which case the property is known as a method.

CODING CHALLENGE 4
Let's remember the first coding challenge where Mark and John compared their BMIs. Let's now implement the same functionality with objects and methods.

For each of them, create an object with properties for their full name, mass, and height
Then, add a method to each object to calculate the BMI. Save the BMI to the object and also return it from the method.
In the end, log to the console who has the highest BMI, together with the full name and the respective BMI. Don't forget they might have the same BMI.
Remember: BMI = mass / height^2 = mass / (height * height). (mass in kg and height in meter).



SOURCE CODE:

<script>

let mark = {
fullName: 'Mark',
mass: 65,
height: 1.22,
calBMI : function(){
this.bmi = this.mass / (this.height * this.height);
return this.bmi;
}

}

let john = {
fullName: 'john',
mass: 65,
height: 1.22,
calBMI : function(){
this.bmi = this.mass / (this.height * this.height);
return this.bmi;
}

}

//DONATION FOR SUPPORT:    PhonePay = vinodbahadur@ybl      GooglePay: vbthapa55@oksbi
 //Believe me all this money will be used to make more quality videos and to make my channel grow. So that I can always provide you awesome free videos :)

console.log("mark: "+mark.calBMI());

console.log("john: "+john.calBMI());

if(mark.bmi > john.bmi){
console.log(mark.fullName+" has higher BMI value "+mark.bmi);

}else if(john.bmi > mark.bmi){
console.log(john.fullName+" has higher BMI value "+john.bmi);
} else{
console.log(john.fullName + " and " +mark.fullName +"  have same BMI value." )
}

</script>

2 comments: