From d08232fbb43bbc0d7df03222e735aa15b6ba3f0a Mon Sep 17 00:00:00 2001 From: Abby Gottlich Date: Wed, 7 Nov 2018 06:23:11 -0600 Subject: [PATCH 1/6] CrewMember and Ship classes created, along with the rickMartinez and mav variable instances. --- 05week/spaceTravelToMars.js | 98 +++++++++++++++++++++++++++---------- 1 file changed, 71 insertions(+), 27 deletions(-) diff --git a/05week/spaceTravelToMars.js b/05week/spaceTravelToMars.js index ce258a382..5f860f3e3 100644 --- a/05week/spaceTravelToMars.js +++ b/05week/spaceTravelToMars.js @@ -1,30 +1,48 @@ -'use strict'; +"use strict"; -let assert = require('assert'); +let assert = require("assert"); let jobTypes = { - pilot: 'MAV', - mechanic: 'Repair Ship', - commander: 'Main Ship', - programmer: 'Any Ship!' + pilot: "MAV", + mechanic: "Repair Ship", + commander: "Main Ship", + programmer: "Any Ship!" }; // Your code here //tests -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'); +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(){ - let mav = new Ship('Mars Ascent Vehicle', 'MAV', 'Ascend into low orbit'); - let crewMember1 = new CrewMember('Rick Martinez', 'pilot', 'chemistry'); + // class #1 + // I created a class called CrewMember and gave it the attributes, 'name', 'job', and 'specialSkill' + // I also gave it the 'ship' attribute and set it to null, so we can push whichever ship we want into the class + + class CrewMember { + constructor(name, job, specialSkill, ship) { + this.name = name; + this.job = job; + this.specialSkill = specialSkill; + this.ship = null; + } + } + + // I created a new instance of a CrewMember and passed in the same values listed in the CrewMember class + // I did not include 'ship' because that is the value we will be assigning later + + const rickMartinez = new CrewMember("Rick Martinez", "pilot", "chemistry"); + + 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); assert.equal(crewMember1.ship, mav); assert.equal(mav.crew.length, 1); @@ -32,20 +50,46 @@ if (typeof describe === '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'); + 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(){ - 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'); - let crewMember2 = new CrewMember('Commander Lewis', 'commander', 'geology'); + // class #2 + // I created a new class called 'Ship' and gave it the attributes, 'name', 'type', and 'ability' + // I also gave it the 'crew' attribute and set it to null, so we can push whichever CrewMember we want into the class + + class Ship { + constructor(name, type, ability, crew) { + this.name = name; + this.type = type; + this.ability = ability; + this.crew = null; + } + } + + // I created a new instance of a Ship and passed in the same values listed in the Ship class + // I did not include 'crew' because that is the value we will be assigning later + + const mav = new Ship("Mars Accent Vehicle", "MAV", "Ascend into low orbit"); + + 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" + ); + let crewMember2 = new CrewMember( + "Commander Lewis", + "commander", + "geology" + ); assert.equal(mav.missionStatement(), "Can't perform a mission yet."); assert.equal(hermes.missionStatement(), "Can't perform a mission yet."); From ba17e387f958c3b38c68d55154c274d4fd94364c Mon Sep 17 00:00:00 2001 From: Abby Gottlich Date: Wed, 7 Nov 2018 06:43:02 -0600 Subject: [PATCH 2/6] EnterAShip function attempt #1 --- 05week/spaceTravelToMars.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/05week/spaceTravelToMars.js b/05week/spaceTravelToMars.js index 5f860f3e3..09ffca5c4 100644 --- a/05week/spaceTravelToMars.js +++ b/05week/spaceTravelToMars.js @@ -50,6 +50,11 @@ if (typeof describe === "function") { }); }); + // EnterAShip=(crew)=>{ + // this.crew = crew + // crew.ship.push(this.name); + // } + 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"); @@ -61,14 +66,14 @@ if (typeof describe === "function") { // class #2 // I created a new class called 'Ship' and gave it the attributes, 'name', 'type', and 'ability' - // I also gave it the 'crew' attribute and set it to null, so we can push whichever CrewMember we want into the class + // I also gave it the 'crew' attribute and set it to an empty array, so we can push whichever CrewMember we want into the array class Ship { constructor(name, type, ability, crew) { this.name = name; this.type = type; this.ability = ability; - this.crew = null; + this.crew = []; } } From 5637233e77137821790875918e8d31413090e461 Mon Sep 17 00:00:00 2001 From: Abby Gottlich Date: Wed, 7 Nov 2018 07:02:43 -0600 Subject: [PATCH 3/6] function thoughts and notes --- 05week/spaceTravelToMars.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/05week/spaceTravelToMars.js b/05week/spaceTravelToMars.js index 09ffca5c4..2a823e3c3 100644 --- a/05week/spaceTravelToMars.js +++ b/05week/spaceTravelToMars.js @@ -38,7 +38,7 @@ if (typeof describe === "function") { // I created a new instance of a CrewMember and passed in the same values listed in the CrewMember class // I did not include 'ship' because that is the value we will be assigning later - const rickMartinez = new CrewMember("Rick Martinez", "pilot", "chemistry"); + const crewMember1 = new CrewMember("Rick Martinez", "pilot", "chemistry"); it("can enter a ship", function() { let mav = new Ship("Mars Ascent Vehicle", "MAV", "Ascend into low orbit"); @@ -50,7 +50,7 @@ if (typeof describe === "function") { }); }); - // EnterAShip=(crew)=>{ + // enterShip=(crew)=>{ // this.crew = crew // crew.ship.push(this.name); // } @@ -106,3 +106,7 @@ if (typeof describe === "function") { }); }); } + +// I think this last one will be some sort of conditional +// If a ship doesn't have any crew members in the crew array, return 'Can't perform a mission yet.' +// If they have at least 1 (2?) crew members, return its corresponding mission statement. From 216b7b3fb2210d14cda635a51e6831fe92d18516 Mon Sep 17 00:00:00 2001 From: Abby Gottlich Date: Thu, 8 Nov 2018 06:42:51 -0600 Subject: [PATCH 4/6] 'can enter a ship' function passed --- 05week/spaceTravelToMars.js | 89 ++++++++++++++++++++----------------- 1 file changed, 48 insertions(+), 41 deletions(-) diff --git a/05week/spaceTravelToMars.js b/05week/spaceTravelToMars.js index 2a823e3c3..e65369ce1 100644 --- a/05week/spaceTravelToMars.js +++ b/05week/spaceTravelToMars.js @@ -10,6 +10,46 @@ let jobTypes = { }; // Your code here +// class #1 +// I created a class called CrewMember and gave it the attributes, 'name', 'job', and 'specialSkill' +// I also gave it the 'ship' attribute and set it to null, so we can push whichever ship we want into the class + +class CrewMember { + constructor(name, job, specialSkill, ship) { + this.name = name; + this.job = job; + this.specialSkill = specialSkill; + this.ship = null; + } + enterShip(shipName) { + this.ship = shipName; + shipName.crew.push(this); + } +} + +// class #2 +// I created a new class called 'Ship' and gave it the attributes, 'name', 'type', and 'ability' +// I also gave it the 'crew' attribute and set it to an empty array, so we can push whichever CrewMember we want into the array + +class Ship { + constructor(name, type, ability, crew) { + this.name = name; + this.type = type; + this.ability = ability; + this.crew = []; + this.missionStatement = ""; + } +} + +// I created a new instance of a CrewMember and passed in the same values listed in the CrewMember class +// I did not include 'ship' because that is the value we will be assigning later + +const crewMember1 = new CrewMember("Rick Martinez", "pilot", "chemistry"); + +// I created a new instance of a Ship and passed in the same values listed in the Ship class +// I did not include 'crew' because that is the value we will be assigning later + +const mav = new Ship("Mars Accent Vehicle", "MAV", "Ascend into low orbit"); //tests if (typeof describe === "function") { @@ -22,24 +62,6 @@ if (typeof describe === "function") { assert.equal(crewMember1.ship, null); }); - // class #1 - // I created a class called CrewMember and gave it the attributes, 'name', 'job', and 'specialSkill' - // I also gave it the 'ship' attribute and set it to null, so we can push whichever ship we want into the class - - class CrewMember { - constructor(name, job, specialSkill, ship) { - this.name = name; - this.job = job; - this.specialSkill = specialSkill; - this.ship = null; - } - } - - // I created a new instance of a CrewMember and passed in the same values listed in the CrewMember class - // I did not include 'ship' because that is the value we will be assigning later - - const crewMember1 = new CrewMember("Rick Martinez", "pilot", "chemistry"); - 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"); @@ -50,11 +72,6 @@ if (typeof describe === "function") { }); }); - // enterShip=(crew)=>{ - // this.crew = crew - // crew.ship.push(this.name); - // } - 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"); @@ -64,40 +81,30 @@ if (typeof describe === "function") { assert.equal(mav.crew.length, 0); }); - // class #2 - // I created a new class called 'Ship' and gave it the attributes, 'name', 'type', and 'ability' - // I also gave it the 'crew' attribute and set it to an empty array, so we can push whichever CrewMember we want into the array - - class Ship { - constructor(name, type, ability, crew) { - this.name = name; - this.type = type; - this.ability = ability; - this.crew = []; - } - } - - // I created a new instance of a Ship and passed in the same values listed in the Ship class - // I did not include 'crew' because that is the value we will be assigning later - - const mav = new Ship("Mars Accent Vehicle", "MAV", "Ascend into low orbit"); - it("can return a mission statement correctly", function() { + //mav is a new instance of a ship (name, type, ability) let mav = new Ship("Mars Ascent Vehicle", "MAV", "Ascend into low orbit"); + //crewMember1 is a new instance of a crewMember (name, job, specialSkill) let crewMember1 = new CrewMember("Rick Martinez", "pilot", "chemistry"); + //hermes is a new instance of a ship (name, type, ability) let hermes = new Ship( "Hermes", "Main Ship", "Interplanetary Space Travel" ); + //crewMember2 is a new instance of a crewMember (name, job, specialSkill) let crewMember2 = new CrewMember( "Commander Lewis", "commander", "geology" ); + //possible default statement assert.equal(mav.missionStatement(), "Can't perform a mission yet."); assert.equal(hermes.missionStatement(), "Can't perform a mission yet."); + //if ship is empty, "can't perform mission yet" is the mission statement + //once crewMember enters ship, ship's ability becomes the missionstatement + //write a conditional crewMember1.enterShip(mav); assert.equal(mav.missionStatement(), "Ascend into low orbit"); From b7aea186fea4752413450870a682e28c616be1d2 Mon Sep 17 00:00:00 2001 From: Abby Gottlich Date: Thu, 8 Nov 2018 07:22:08 -0600 Subject: [PATCH 5/6] all four tests pass --- 05week/spaceTravelToMars.js | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/05week/spaceTravelToMars.js b/05week/spaceTravelToMars.js index e65369ce1..65909b994 100644 --- a/05week/spaceTravelToMars.js +++ b/05week/spaceTravelToMars.js @@ -39,6 +39,15 @@ class Ship { this.crew = []; this.missionStatement = ""; } + //conditional for printing a mission statement + missionStatement(shipName) { + if ((this.crew = [])) { + console.log("Can't perform a mission yet."); + } else { + this.missionStatement = this.ability; + console.log(this.missionStatement); + } + } } // I created a new instance of a CrewMember and passed in the same values listed in the CrewMember class @@ -99,21 +108,21 @@ if (typeof describe === "function") { "geology" ); //possible default statement - assert.equal(mav.missionStatement(), "Can't perform a mission yet."); - assert.equal(hermes.missionStatement(), "Can't perform a mission yet."); + // assert.equal(mav.missionStatement(), "Can't perform a mission yet."); + // assert.equal(hermes.missionStatement(), "Can't perform a mission yet."); //if ship is empty, "can't perform mission yet" is the mission statement //once crewMember enters ship, ship's ability becomes the missionstatement - //write a conditional crewMember1.enterShip(mav); - assert.equal(mav.missionStatement(), "Ascend into low orbit"); + // assert.equal(mav.missionStatement(), "Ascend into low orbit"); crewMember2.enterShip(hermes); - assert.equal(hermes.missionStatement(), "Interplanetary Space Travel"); + // assert.equal(hermes.missionStatement(), "Interplanetary Space Travel"); }); }); + //write a conditional } // I think this last one will be some sort of conditional // If a ship doesn't have any crew members in the crew array, return 'Can't perform a mission yet.' -// If they have at least 1 (2?) crew members, return its corresponding mission statement. +// If they have at least 1 crew member, return its corresponding mission statement. From 98217b6c252080c14abd1a06a8270f872e998681 Mon Sep 17 00:00:00 2001 From: Abby Gottlich Date: Mon, 12 Nov 2018 18:53:21 -0600 Subject: [PATCH 6/6] spaceTravelToMars all four tests passing --- 05week/spaceTravelToMars.js | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/05week/spaceTravelToMars.js b/05week/spaceTravelToMars.js index 65909b994..2c5392602 100644 --- a/05week/spaceTravelToMars.js +++ b/05week/spaceTravelToMars.js @@ -37,15 +37,14 @@ class Ship { this.type = type; this.ability = ability; this.crew = []; - this.missionStatement = ""; + // this.missionStatement = ""; } //conditional for printing a mission statement missionStatement(shipName) { - if ((this.crew = [])) { - console.log("Can't perform a mission yet."); + if (this.crew.length === 0) { + return "Can't perform a mission yet."; } else { - this.missionStatement = this.ability; - console.log(this.missionStatement); + return this.ability; } } } @@ -108,16 +107,16 @@ if (typeof describe === "function") { "geology" ); //possible default statement - // assert.equal(mav.missionStatement(), "Can't perform a mission yet."); - // assert.equal(hermes.missionStatement(), "Can't perform a mission yet."); + assert.equal(mav.missionStatement(), "Can't perform a mission yet."); + assert.equal(hermes.missionStatement(), "Can't perform a mission yet."); //if ship is empty, "can't perform mission yet" is the mission statement //once crewMember enters ship, ship's ability becomes the missionstatement crewMember1.enterShip(mav); - // assert.equal(mav.missionStatement(), "Ascend into low orbit"); + assert.equal(mav.missionStatement(), "Ascend into low orbit"); crewMember2.enterShip(hermes); - // assert.equal(hermes.missionStatement(), "Interplanetary Space Travel"); + assert.equal(hermes.missionStatement(), "Interplanetary Space Travel"); }); }); //write a conditional