// ---------- class Person ---------
function Person(namePerson, age, height, sex, weight, nationality) {
this.names = namePerson[0].toUpperCase() + namePerson.substring(1); //convert first Letter to uppercase
this.age = age;
this.height = height;
this.sex = sex;
this.weight = weight;
this.nationality = nationality;
// -------- function to presentation in console --------
this.presentation = function () {
let pre = "My name is: " + this.names +"\n"+
"My age is: " + this.age +" year\n" +
"My height is: " + this.height +" cm\n" +
"My sex is: " + this.sex +"\n" +
"My weight is: " + this.weight +" kg\n" +
"My nationality is: " + this.nationality +"\n" +
"My BMI is: " + this.cal_BMI() +"\n" ;
return pre;
}
// -------- function to calculator BMI --------
this.cal_BMI = function () {
return Math.round(this.weight / ((this.height/100)**2)); // BMI = w(kg)/h(m)^2 --> height from cm to m
}
}
let myPerson = new Person("mohammad", 29, 180, "men", 75, "iranian");
console.log(myPerson.presentation());