We have learned Object-oriented programming and how class and inheritance work in JavaScript. Now let's work with our Viking friends, applying all of the concepts we have just learned.
Create a Pull Request so that your TAs can check your work.
Test, test, test!
This LAB is equipped with unit tests to provide automated feedback on your lab progress.
This time you will be working with the tests from the beginning and use them alongside the iteration instructions.
Please, open your terminal, change directories into the root of the lab, and run npm install to install the test runner. Next, run the npm run test:watch command to run the automated tests.
$ cd lab-javascript-vikings
$ npm install
$ npm run test:watch
Open the resulting lab-solution.html file with the Live Server VSCode extension to see the test results. You will see that most of the tests are failing. Let's get to work to make all of them pass!
Note: The testing environment and the lab-solution.html page don’t allow printing the console logs in the browser.
To see the console.log outputs you write in the viking.js file, open the index.html file using the Live Server VSCode extension.
Instructions
You will work on the src/viking.js file.
Your task is to write the correct code in the src/viking.js file to make the tests pass. In this file, you will find the following starter code:
Let's have a look at the first test case together to get you started.
The first test case says that "Soldier class >> should receive 2 arguments (health & strength)", so we have to write the correct code to pass this test. Let's make the Soldier class receive two arguments:
A Saxon is a weaker kind of Soldier. Unlike a Viking, a Saxon has no name. Their receiveDamage() method will also be different than the original Soldier version.
Modify the Saxon, constructor function, have it inherit from Soldier and re-implement the receiveDamage() method for Saxon.
inheritance
Saxon should extend Soldier
class
You don't have to include constructor method since this class will inherit perfectly from the parents class, both, the health and the strength (it extends Soldier class
请发表评论