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
78 changes: 70 additions & 8 deletions 05week/spaceTravelToMars.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,82 @@ let jobTypes = {
programmer: 'Any Ship!'
};

// Your code here
class CrewMember {
constructor(name, job, specialSkill) {
this.name = name;
this.job = job;
this.specialSkill = specialSkill;
this.ship = null;
}

printOutName() {
console.log(this.name)
}

// assignShip() {
// if (this.job == 'pilot') {
// this.ship = 'MAV'
// }
// if (this.job == 'mechanic') {
// this.ship = 'Repair Ship'
// }
// if (this.job == 'commander') {
// this.ship = 'Main Ship'
// }
// if (this.job == 'programmer') {
// this.ship = 'Any Ship!'
// }
// }

enterShip(ship) {
this.ship = ship
ship.crew.push(this)
}
}

class Ship {
constructor(name, type, ability) {
this.name = name;
this.type = type;
this.ability = ability;
this.crew = []
}
missionStatement() {
if (this.crew.length < 1) {
return ("Can't perform a mission yet.")

Choose a reason for hiding this comment

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

parentheses are not needed here

} else {
return (this.ability)
}

}
}

const crewMember1 = new CrewMember('Rick Martinez', 'pilot', 'chemistry');
const crewMember2 = new CrewMember('Commander Lewis', 'commander', 'geology');
const mav = new Ship('Mars Ascent Vehicle', 'MAV', 'Ascend into low orbit');
const hermes = new Ship('Hermes', 'Main Ship', 'Interplanetary Space Travel');
// crewMember1.assignShip()
// console.log(crewMember1.ship)
// crewMember2.assignShip()
// console.log(crewMember2.ship)
// mav.missionStatement();
// hermes.missionStatement();
// crewMember1.enterShip()
// crewMember2.enterShip(hermes)
// mav.missionStatement();
// hermes.missionStatement();
//tests
if (typeof describe === 'function'){
describe('CrewMember', function(){
it('should have a name, a job, a specialSkill and ship upon instantiation', function(){
if (typeof describe === 'function') {
describe('CrewMember', function() {
it('should have a name, a job, a specialSkill and ship upon instantiation', function() {
var crewMember1 = new CrewMember('Rick Martinez', 'pilot', 'chemistry');
assert.equal(crewMember1.name, 'Rick Martinez');
assert.equal(crewMember1.job, 'pilot');
assert.equal(crewMember1.specialSkill, 'chemistry');
assert.equal(crewMember1.ship, null);
});

it('can enter a ship', function(){
it('can enter a ship', function() {
let mav = new Ship('Mars Ascent Vehicle', 'MAV', 'Ascend into low orbit');
let crewMember1 = new CrewMember('Rick Martinez', 'pilot', 'chemistry');
crewMember1.enterShip(mav);
Expand All @@ -32,16 +94,16 @@ if (typeof describe === 'function'){
});
});

describe('Ship', function(){
it('should have a name, a type, an ability and an empty crew upon instantiation', function(){
describe('Ship', function() {
it('should have a name, a type, an ability and an empty crew upon instantiation', function() {
let mav = new Ship('Mars Ascent Vehicle', 'MAV', 'Ascend into low orbit');
assert.equal(mav.name, 'Mars Ascent Vehicle');
assert.equal(mav.type, 'MAV');
assert.equal(mav.ability, 'Ascend into low orbit');
assert.equal(mav.crew.length, 0);
});

it('can return a mission statement correctly', function(){
it('can return a mission statement correctly', function() {
let mav = new Ship('Mars Ascent Vehicle', 'MAV', 'Ascend into low orbit');
let crewMember1 = new CrewMember('Rick Martinez', 'pilot', 'chemistry');
let hermes = new Ship('Hermes', 'Main Ship', 'Interplanetary Space Travel');
Expand Down