Object Methods
Add a method called
describeto themyCountryobject. This method will log a string to the console, similar to the string logged in the previous assignment, but this time using the 'this' keyword.Call the
describemethod.Add a method called
checkIslandto themyCountryobject. This method will set a new property on the object, calledisIsland.isIslandwill betrueif there are no neighbouring countries, andfalseif there are. Use the ternary operator to set the property.
const myCountry = {
country: 'Finland',
capital: 'Helsinki',
language: 'finnish',
population: 6,
neighbours: ['Norway', 'Sweden', 'Russia'],
describe: function() {
console.log(
`${this.country} has ${this.population} million ${this.language}-speaking people, ${this.neighbours.length} neighbouring countries and a capital called ${this.capital}.`
);
},
checkIsland: function() {
this.isIsland = this.neighbours.length === 0 ? true : false;
// Even simpler version (see why this works...)
// this.isIsland = !Boolean(this.neighbours.length);
}
};
myCountry.describe();
myCountry.checkIsland();
console.log(myCountry);