• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

ironhack-labs/lab-javascript-vikings: A JavaScript exercise to practice Object O ...

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称:

ironhack-labs/lab-javascript-vikings

开源软件地址:

https://github.com/ironhack-labs/lab-javascript-vikings

开源编程语言:

JavaScript 97.3%

开源软件介绍:

logo_ironhack_blue 7

LAB | JS Vikings

giphy

Introduction

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.


Requirements

  • Fork this repo.
  • Clone this repo.

Submission

  • Upon completion, run the following commands:
$ git add .
$ git commit -m "Solved lab"
$ git push origin master
  • 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:

// Soldier
class Soldier {}

// Viking
class Viking {}

// Saxon
class Saxon {}

// War
class War {}

Iteration 0: First test

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:

// Soldier
class Soldier {
  constructor(health, strength) {}
}

// Viking
class Viking {}

// Saxon
class Saxon {}

// War
class War {}

Iteration 1: Soldier

Modify the Soldier class and add 2 methods to it: attack(), and receiveDamage().

class

  • should receive 2 arguments (health & strength)
  • should receive the health property as its 1st argument
  • should receive the strength property as its 2nd argument

attack() method

  • should be a function
  • should receive 0 arguments
  • should return the strength property of the Soldier

receiveDamage() method

  • should be a function
  • should receive 1 argument (the damage)
  • should remove the received damage from the health property
  • shouldn't return anything

Iteration 2: Viking

A Viking is a Soldier with an additional property, their name. They also have a different receiveDamage() method and new method, battleCry().

Modify the Viking class, have it inherit from Soldier, re-implement the receiveDamage() method for Viking, and add a new battleCry() method.

inheritance

  • Viking should extend Soldier

class

  • should receive 3 arguments (name, health & strength)
  • should receive the name property as its 1st argument
  • should receive the health property as its 2nd argument
  • should receive the strength property as its 3rd argument

attack() method

(This method should be inherited from Soldier, no need to re-implement it.)

  • should be a function
  • should receive 0 arguments
  • should return the strength property of the Viking

receiveDamage() method

This method needs to be re-implemented for Viking because the Viking version needs to have different return values.

  • should be a function
  • should receive 1 argument (the damage)
  • should remove the received damage from the health property
  • if the Viking is still alive, it should return "NAME has received DAMAGE points of damage"
  • if the Viking dies, it should return "NAME has died in act of combat"

battleCry() method

Learn more about battle cries.

  • should be a function
  • should receive 0 arguments
  • should return "Odin Owns You All!"

Iteration 3: Saxon

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

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap