-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcountry.js
More file actions
26 lines (24 loc) · 880 Bytes
/
country.js
File metadata and controls
26 lines (24 loc) · 880 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
function makeCountry(name, continent, visited = false) {
return {
name,
continent,
getDescription() {
if (this.visited) {
return `${this.name} is located in ${this.continent}. I have visited ${this.name};`;
} else {
return `${this.name} is located in ${this.continent}. I haven't visited ${this.name};`;
}
},
visited,
visitCountry() {
this.visited = true;
},
};
}
let chile = makeCountry('The Republic of Chile', 'South America');
let canada = makeCountry('Canada', 'North America');
let southAfrica = makeCountry('The Republic of South Africa', 'Africa');
console.log(canada.getDescription()); // "Canada is located in North America. I haven't visited Canada."
canada.visitCountry();
console.log(canada)
console.log(canada.getDescription()); // "Canada is located in North America. I have visited Canada."