-
-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathpirateLoot.js
36 lines (26 loc) · 1.16 KB
/
pirateLoot.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/*
You are a leader of a small pirate crew. And you have a plan. With the help of OOP you wish to make a pretty efficient system to identify ships with a heavy booty on board.
Unfortunattely for you, people weigh a lot this days, so how do you know if a ship if full of gold and not people?
You begin with writing a generic Ship class:
function Ship(draft,crew) {
this.draft = draft;
this.crew = crew;
}
Every time your spies see a new ship enter the dock, they will create a new ship object based on their observations:
draft - an estimate of the ship's weight based on how low it is in the water
crew - the count of crew on board
var titanic = new Ship(15, 10);
Taking into account that an average crew member on board adds 1.5 units to the draft, a ship that has a draft of more than 20 without crew is considered worthy to loot. Any ship weighing that much must have a lot of booty!
Add the method
isWorthIt
to decide if the ship is worthy to loot. For example:
titanic.isWorthIt() // return false
*/
//Answer//
function Ship(draft,crew) {
this.draft = draft;
this.crew = crew;
}
Ship.prototype.isWorthIt = function Ship(draft,crew) {
return this.draft-(this.crew*1.5)>20
}