Task using OOPS
Write a JS function that display the bio data (firstName, LastName, age,email) of 3 Persons as shown in table
Person | First Name | Last Name | Age | |
Person 1 | Shairy | Kalra | 32 | er.shairykalra@gmail.com |
Person 2 | Etudepro | |||
Person 3 | Dummy Name | 25 |
Solutions:
<script>
class Person {
constructor(firstName, lastName, age, email)
{
this.firstName = firstName;
this.lastName = lastName;
this.age = age;
this.email = email;
}
Display()
{
document.write("First Name :"+this.firstName+"<br>");
document.write(" Last Name :"+this.lastName+"<br>");
document.write("Age :"+this.age+"<br>");
document.write("Email :"+this.email+"<br>");
document.write("<hr>");
}
}
let object1=new Person("Shairy", "Kalra", 32, "er.shairykalra@gmail.com");
object1.Display();
let object2=new Person("Etudepro");
object2.Display();
let object3=new Person("Dummy Name","", 25);
object3.Display();
</script>