- Open your command-line application and navigate to your workspace.
- Create a new folder named 07-03-defining-methods.
- Copy or create an index.html that loads and runs a main function from main.js.
- Create a main.js with a class named Rocket, which assigns a name property upon construction:
// main.js
class Rocket {
constructor(name) {
this.name = name;
}
}
- Add a method named takeoff that accepts an option countdown argument. The body of the method should log a message before and after a timeout:
// main.js
class Rocket {
// ...
takeOff(countdown = 1000) {
console.log(this.name + ' starting countdown.');
setTimeout(() => {
console.log(`Blastoff! ${this.name} has taken off`);
}, countdown);
}
}
- Add a main function that creates two instances and then calls their takeOff methods:
// main.js
export function main() {
const saturnV = new Rocket('Saturn V');
const falconHeavy = new Rocket('Falcon Heavy');
saturnV.takeOff(500);
falconHeavy.takeOff();
}
- Start your Python web server and open the following link in your browser:
http://localhost:8000/.
- You will see the following output:
..................Content has been hidden....................
You can't read the all page of ebook, please click
here login for view all page.