Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 71 additions & 0 deletions MM/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
'use strict'

class Ship {
crew = [];
constructor(name, type, ablility) {
this.name = name;
this.type = type;
this.ablility = ablility;
};
missionStatement() {
let msg;
if (this.crew.length > 0) {
msg = `We have ${this.crew.length} crew member(s). Ready to ${this.ablility}`
}
else {
msg = "No Crew. Can't do mission!"
}
console.log(msg)
}
};

class CrewMember {
constructor(name, job, skill) {
this.name = name;
this.job = job;
this.skill = skill;
}
enterShip(ship) {
this.ship = ship;
ship.crew.push(this);
};
};

let s1 = new Ship('Heremes', 'Cargo', 'Time Travel')
let u1 = new CrewMember('David', 'Pilot', 'Chemist')
let u2 = new CrewMember('Maria', 'Tech', 'Barber')


console.log(s1)
/*Ship {crew: [], name: 'Heremes', type: 'Cargo', ablility: 'Time Travel'}*/

u1.enterShip(s1)
console.log(u1)
/*CrewMember {
name: 'David', job: 'Pilot', skill: 'Chemist',
ship: Ship { crew: [ [Circular] ], name: 'Heremes', type: 'Cargo', ablility: 'Time Travel'}
}*/

u2.enterShip(s1)
console.log(u2)
/*CrewMember {
name: 'Maria', job: 'Tech', skill: 'Barber',
ship: Ship {crew: [ [CrewMember], [Circular] ], name: 'Heremes', type: 'Cargo', ablility: 'Time Travel'}
}*/


console.log(s1)
/*Ship {
crew: [
CrewMember {name: 'David', job: 'Pilot', skill: 'Chemist', ship: [Circular]},
CrewMember {name: 'Maria', job: 'Tech', skill: 'Barber', ship: [Circular]}
],
name: 'Heremes', type: 'Cargo', ablility: 'Time Travel'
}*/

s1.missionStatement()
//We have 2 crew member(s). Ready to Time Travel


Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am missing the tests from the code sample that was provided.