JSFiddle - React, Tailwind, and code Playground
by Aniket Suryavanshi
JavaScript
/*
1. Create a class Human.
a. Constructor of Human Takes in three Params: ssn , firstName , lastName
b. Make ssn a private property of Human.
c. Expose a getter methods getSSN , getFirstName & getLastName.
d. Expose a setter methods setFirstName & setLastName.
e. Expose a method getFullName
2. Create a class Asian derived from Human.
a. Constructor of Human Takes in three Params: ssn , firstName , lastName , country.
b. Expose a method getCountry.
*/
function Human( ssn , firstName , lastName ) {
//Write Code Here.
this.getSSN = function() { return ssn; };
this.firstName = firstName;
this.lastName = lastName;
};
//Write Code Here.
Human.prototype.getFirstName = function() {
return this.firstName;
};
Human.prototype.getLastName = function() {
return this.lastName;
};
Human.prototype.setFirstName = function(fName) {
this.firstName = fName;
};
Human.prototype.setLastName = function(lName) {
this.lastName = lName;
};
Human.prototype.getFullName = function(lName) {
return this.firstName + ' ' + this.lastName;
};
function Asian( ssn, firstName , lastName , country ) {
//Write Code Here.
this.country = country;
this.getSSN = function() { return ssn; };
};
//Write Code Here.
Asian.prototype = Object.create(Human.prototype);
Asian.prototype.constructor = Asian;
Human.prototype.getCountry = function(lName) {
return this.country;
};
//--------------------- Test Cases ------------------//
//Test Cases.
var allPased = true;
var h1 = new Human("SA-DA-123" , "Mohan" , "Kumar");
var h2 = new Human("SA-DA-122" , "Satnis" , "Law");
var a1 = new Asian("IN-DA-443" , "Saorabh" , "Kumar" , "India" );
var a2 = new Asian("IN-DA-344" , "Thahir" , "Khan" , "India" );
var a3 = new Asian("CN-DA-344" , "Qin Shi" , "Huang" , "China" );
if( a1.getSSN == a2.getSSN ) {
allPased = false;
alert("Failed! SSN is not a private variable");
}
if( h1.getFullName != h2.getFullName || h1.getFirstName !=...