- Create a new directory and change directory into it.
- Create a file called
character.js
- Create a file called
planet.js
- Create a file called
index.js
- run
npm init -y
- run
npm install axios
- require
axios
inindex.js
.
- Create a class called Character in the
character.js
file. - Define a constructor method that takes parameters
name, height, mass, gender
- Export this class
- Create a class called Planet in the
planet.js
file - Define a constructor method that takes parameters
name, gravity, population
- Export this class
- Import both
character.js
andplanet.js
- Define a
function
namedcreateObject
that takes 2 argumentstype, id
- If the
type
argument is equals to 'planet' you will make an asynchronous request to the Star Wars api to get a planet with id equals to theid
argument. After the request resolves create a new instance of thePlanet class
with the data you received from the request. - If the
type
argument is equals to 'character' then make a request to the Star Wars api to build a character.