JSFiddle - React, Tailwind, and code Playground
by mrunali tatkundawar
JavaScript
function Person(first, last, age, gender, interests,company, position) {
this.name = {
first,
last
};
this.age = age;
this.gender = gender;
this.interests = interests;
this.company = company;
this.position = position;
};
Person.prototype.bio = function() {
//var string = this.name.first + ' ' + this.name.last + ' is ' + this.age + ' years old. ';
var string = this.name.first + ' ' + this.name.last + ' ' +'working in a ' + this.company +' ' +'company ' + 'as a' + this.position +'.'
var pronoun;
if(this.gender === 'male' || this.gender === 'Male' || this.gender === 'm' || this.gender === 'M') {
pronoun = 'He likes ';
} else if(this.gender === 'female' || this.gender === 'Female' || this.gender === 'f' || this.gender === 'F') {
pronoun = 'She likes ';
} else {
pronoun = 'They like ';
}
string += pronoun;
if(this.interests.length === 1) {
string += this.interests[0] + '.';
} else if(this.interests.length === 2) {
string += this.interests[0] + ' and ' + this.interests[1] + '.';
} else {
for(var i = 0; i < this.interests.length; i++) {
if(i === this.interests.length - 1) {
string += 'and ' + this.interests[i] + '.';
} else {
string += this.interests[i] + ', ';
}
}
}
alert(string);
};
Person.prototype.introduction= function() {
alert('Hi! I\'m ' + this.name.first + '.');
};
Person.prototype.farewell = function() {
alert(this.name.first + ' has left the building. Bye for now!');
}
Person.prototype.birthyear = function () {
var currentyear = new Date().getFullYear();
alert( currentyear - this.age);
}
var person1 = new Person('Mayuri', 'wagh', 23, 'female', ['music', 'dancing', 'badminton'],'Infosys','Software Engineer');
person1.birthyear();
person1.bio();
person1.introduction();
person1.farewell();