课程: JavaScript Practice: Object-Oriented Programming
Solution: Create a country with classes - JavaScript教程
课程: JavaScript Practice: Object-Oriented Programming
Solution: Create a country with classes
- [Instructor] To create the Country class, we'll use JavaScript class notation. The Country class constructor takes four parameters: name, continent, currency, and population. We'll place these inside the constructor function. To get the overview of a country, we can create a getOverview function inside of a class. This will return the template literal provided in the requirement section of this challenge. Lastly, we'll create the setPopulation function on the class. It takes one parameter newPopulation and updates the population property. If we run our solution, we can see all the tests are passing.