Thursday, August 19, 2021

Javascript object and method example.

//Defining johnObj  

var johnObj = {

    calJonBMI: function () { //method

        this.BMI = this.mass / (this.height * this.height);

        return this.BMI;

    }

};

//setting properties later

johnObj.fullName = "john cena";

johnObj.mass = 40;

johnObj.height = 5.6;

console.log(johnObj);

console.log(johnObj.fullName+"'s BMI is:"+johnObj.calJonBMI());

//Defining markObj

var markObj = {

    calJonBMI: function () {

        this.BMI = this.mass / (this.height * this.height);

        return this.BMI;

    }

};

//setting properties

markObj.fullName = "mark waugh";

markObj.mass = 45;

markObj.height = 6.5;

console.log(markObj);

console.log(markObj.fullName+"'s BMI is:"+markObj.calJonBMI());

if(johnObj.BMI>markObj.BMI){

  console.log(johnObj.fullName+" BMI is greater than     "+markObj.fullName);

}

else if(markObj.BMI>johnObj.BMI){

  console.log(markObj.fullName+" BMI is greater than             "+johnObj.fullName);

}

else{

 console.log(markObj.fullName+" BMI and"+johnObj.fullName+" are     equal");

}

No comments:

Post a Comment

Element of a good table (Ref: Database design mere mortals by Michael J. Hernandez)

  Elements of the Ideal Table: It represents a single subject, which can be an object or event that reduces the risk of potential data integ...