From ee11f844da80040a2be5472f7be5c50b7954deb2 Mon Sep 17 00:00:00 2001 From: Jim Flores Date: Mon, 19 Aug 2019 13:32:23 -0500 Subject: [PATCH 01/13] Added soultions to exercises 1 - 5. --- exercises/SpaceLocation.js | 10 ++++++++++ exercises/SpaceLocation.ts | 9 +++++++++ exercises/part1-2.js | 14 ++++++++++++++ exercises/part1-2.ts | 17 +++++++++++++++++ exercises/part3.js | 15 +++++++++++++++ exercises/part3.ts | 18 ++++++++++++++++++ exercises/part4.js | 18 ++++++++++++++++++ exercises/part4.ts | 25 +++++++++++++++++++++++++ exercises/part5.js | 26 ++++++++++++++++++++++++++ exercises/part5.ts | 32 ++++++++++++++++++++++++++++++++ exercises/parts1-3.ts | 15 --------------- exercises/parts4-5.ts | 20 -------------------- 12 files changed, 184 insertions(+), 35 deletions(-) create mode 100644 exercises/SpaceLocation.js create mode 100644 exercises/part1-2.js create mode 100644 exercises/part1-2.ts create mode 100644 exercises/part3.js create mode 100644 exercises/part3.ts create mode 100644 exercises/part4.js create mode 100644 exercises/part4.ts create mode 100644 exercises/part5.js create mode 100644 exercises/part5.ts delete mode 100644 exercises/parts1-3.ts delete mode 100644 exercises/parts4-5.ts diff --git a/exercises/SpaceLocation.js b/exercises/SpaceLocation.js new file mode 100644 index 00000000..f80d96d3 --- /dev/null +++ b/exercises/SpaceLocation.js @@ -0,0 +1,10 @@ +"use strict"; +exports.__esModule = true; +var SpaceLocation = /** @class */ (function () { + function SpaceLocation(name, kilometersAway) { + this.name = name; + this.kilometersAway = kilometersAway; + } + return SpaceLocation; +}()); +exports.SpaceLocation = SpaceLocation; diff --git a/exercises/SpaceLocation.ts b/exercises/SpaceLocation.ts index e69de29b..8c83fe40 100644 --- a/exercises/SpaceLocation.ts +++ b/exercises/SpaceLocation.ts @@ -0,0 +1,9 @@ +export class SpaceLocation { + kilometersAway: number; + name: string; + + constructor(name: string, kilometersAway: number) { + this.name = name; + this.kilometersAway = kilometersAway; + } +} \ No newline at end of file diff --git a/exercises/part1-2.js b/exercises/part1-2.js new file mode 100644 index 00000000..f75c7079 --- /dev/null +++ b/exercises/part1-2.js @@ -0,0 +1,14 @@ +// URL for the instructions: +// https://education.launchcode.org/intro-to-professional-web-dev/chapters/typescript/exercises.html +// Part 1: Add the 5 variables here +var spacecraftName = "Discovery"; +var speedMph = 17500; +var kilometersToMars = 225000000; +var kilometersToTheMoon = 384400; +var milesPerKilometer = 0.621; +// Code part 2 here: +var milesToMars = kilometersToMars * milesPerKilometer; +var hoursToMars = milesToMars / speedMph; +var daysToMars = hoursToMars / 24; +// Code the output statement here (use a template literal): +console.log(spacecraftName + " would take " + daysToMars + " to get to Mars."); diff --git a/exercises/part1-2.ts b/exercises/part1-2.ts new file mode 100644 index 00000000..b687bb36 --- /dev/null +++ b/exercises/part1-2.ts @@ -0,0 +1,17 @@ +// URL for the instructions: +// https://education.launchcode.org/intro-to-professional-web-dev/chapters/typescript/exercises.html + +// Part 1: Add the 5 variables here +let spacecraftName: string = "Discovery"; +let speedMph: number = 17500; +let kilometersToMars: number = 225000000; +let kilometersToTheMoon: number = 384400; +let milesPerKilometer: number = 0.621; + +// Code part 2 here: +let milesToMars: number = kilometersToMars*milesPerKilometer; +let hoursToMars: number = milesToMars/speedMph; +let daysToMars: number = hoursToMars/24; + +// Code the output statement here (use a template literal): +console.log(`${spacecraftName} would take ${daysToMars} to get to Mars.`); \ No newline at end of file diff --git a/exercises/part3.js b/exercises/part3.js new file mode 100644 index 00000000..cd1acc06 --- /dev/null +++ b/exercises/part3.js @@ -0,0 +1,15 @@ +// URL for the instructions: +// https://education.launchcode.org/intro-to-professional-web-dev/chapters/typescript/exercises.html +var spacecraftName = "Discovery"; +var speedMph = 17500; +var kilometersToMars = 225000000; +var kilometersToTheMoon = 384400; +var milesPerKilometer = 0.621; +// Part 3 - Define the 'getDaysToLocation' function here: +function getDaysToLocation(kilometersAway) { + var milesAway = kilometersAway * milesPerKilometer; + var hours = milesAway / speedMph; + return hours / 24; +} +// Call the function and print the output here: +console.log(spacecraftName + " would take " + getDaysToLocation(kilometersToMars) + " to get to Mars."); diff --git a/exercises/part3.ts b/exercises/part3.ts new file mode 100644 index 00000000..b44eaa74 --- /dev/null +++ b/exercises/part3.ts @@ -0,0 +1,18 @@ +// URL for the instructions: +// https://education.launchcode.org/intro-to-professional-web-dev/chapters/typescript/exercises.html + +let spacecraftName: string = "Discovery"; +let speedMph: number = 17500; +let kilometersToMars: number = 225000000; +let kilometersToTheMoon: number = 384400; +let milesPerKilometer: number = 0.621; + +// Part 3 - Define the 'getDaysToLocation' function here: +function getDaysToLocation(kilometersAway: number): number { + let milesAway: number = kilometersAway * milesPerKilometer; + let hours: number = milesAway / speedMph; + return hours / 24; +} + +// Call the function and print the output here: +console.log(`${spacecraftName} would take ${getDaysToLocation(kilometersToMars)} to get to Mars.`); \ No newline at end of file diff --git a/exercises/part4.js b/exercises/part4.js new file mode 100644 index 00000000..6da2e279 --- /dev/null +++ b/exercises/part4.js @@ -0,0 +1,18 @@ +var kilometersToMars = 225000000; +var kilometersToTheMoon = 384400; +// Part 4 - Define your Spacecraft class here: +var Spacecraft = /** @class */ (function () { + function Spacecraft(name, speedMph) { + this.milesPerKilometer = 0.621; + this.name = name; + this.speedMph = speedMph; + } + Spacecraft.prototype.getDaysToLocation = function (kilometersAway) { + var milesAway = kilometersAway * this.milesPerKilometer; + var hours = milesAway / this.speedMph; + return hours / 24; + }; + return Spacecraft; +}()); +var spaceShuttle = new Spacecraft('Discovery', 17500); +console.log(spaceShuttle.name + " would take " + spaceShuttle.getDaysToLocation(kilometersToMars) + " days to get to Mars."); diff --git a/exercises/part4.ts b/exercises/part4.ts new file mode 100644 index 00000000..02262a08 --- /dev/null +++ b/exercises/part4.ts @@ -0,0 +1,25 @@ +let kilometersToMars: number = 225000000; +let kilometersToTheMoon: number = 384400; + +// Part 4 - Define your Spacecraft class here: +class Spacecraft { + milesPerKilometer: number = 0.621; + name: string; + speedMph: number; + + constructor (name: string, speedMph: number) { + this.name = name; + this.speedMph = speedMph; + } + + getDaysToLocation(kilometersAway: number): number { + let milesAway: number = kilometersAway * this.milesPerKilometer; + let hours: number = milesAway / this.speedMph; + return hours / 24; + } + +} + +let spaceShuttle = new Spacecraft('Discovery', 17500); + +console.log(`${spaceShuttle.name} would take ${spaceShuttle.getDaysToLocation(kilometersToMars)} days to get to Mars.`); diff --git a/exercises/part5.js b/exercises/part5.js new file mode 100644 index 00000000..657b9acb --- /dev/null +++ b/exercises/part5.js @@ -0,0 +1,26 @@ +"use strict"; +exports.__esModule = true; +// Part 5 - Add your import statement to line 2: +var SpaceLocation_1 = require("./SpaceLocation"); +var kilometersToMars = 225000000; +var kilometersToTheMoon = 384400; +// Part 4 - Define your Spacecraft class here: +var Spacecraft = /** @class */ (function () { + function Spacecraft(name, speedMph) { + this.milesPerKilometer = 0.621; + this.name = name; + this.speedMph = speedMph; + } + Spacecraft.prototype.getDaysToLocation = function (kilometersAway) { + var milesAway = kilometersAway * this.milesPerKilometer; + var hours = milesAway / this.speedMph; + return hours / 24; + }; + Spacecraft.prototype.printDaysToLocation = function (location) { + console.log(this.name + " would take " + this.getDaysToLocation(location.kilometersAway) + " days to get to " + location.name + "."); + }; + return Spacecraft; +}()); +var spaceShuttle = new Spacecraft('Discovery', 17500); +spaceShuttle.printDaysToLocation(new SpaceLocation_1.SpaceLocation('Mars', kilometersToMars)); +spaceShuttle.printDaysToLocation(new SpaceLocation_1.SpaceLocation('the Moon', kilometersToTheMoon)); diff --git a/exercises/part5.ts b/exercises/part5.ts new file mode 100644 index 00000000..ebe1b0b3 --- /dev/null +++ b/exercises/part5.ts @@ -0,0 +1,32 @@ +// Part 5 - Add your import statement to line 2: +import { SpaceLocation } from './SpaceLocation'; + +let kilometersToMars: number = 225000000; +let kilometersToTheMoon: number = 384400; + +// Part 4 - Define your Spacecraft class here: +class Spacecraft { + milesPerKilometer: number = 0.621; + name: string; + speedMph: number; + + constructor (name: string, speedMph: number) { + this.name = name; + this.speedMph = speedMph; + } + + getDaysToLocation(kilometersAway: number): number { + let milesAway: number = kilometersAway * this.milesPerKilometer; + let hours: number = milesAway / this.speedMph; + return hours / 24; + } + + printDaysToLocation(location: SpaceLocation) { + console.log(`${this.name} would take ${this.getDaysToLocation(location.kilometersAway)} days to get to ${location.name}.`); + } +} + +let spaceShuttle = new Spacecraft('Discovery', 17500); + +spaceShuttle.printDaysToLocation(new SpaceLocation('Mars', kilometersToMars)); +spaceShuttle.printDaysToLocation(new SpaceLocation('the Moon', kilometersToTheMoon)); diff --git a/exercises/parts1-3.ts b/exercises/parts1-3.ts deleted file mode 100644 index 830b4fe1..00000000 --- a/exercises/parts1-3.ts +++ /dev/null @@ -1,15 +0,0 @@ -// URL for the instructions: -// https://education.launchcode.org/intro-to-professional-web-dev/chapters/typescript/exercises.html - -// Part 1: Add the 5 variables here - - - - - -// Code part 2 here: - - - - -// Part 3: Define the 'getDaysToLocation' function here: diff --git a/exercises/parts4-5.ts b/exercises/parts4-5.ts deleted file mode 100644 index 90f12597..00000000 --- a/exercises/parts4-5.ts +++ /dev/null @@ -1,20 +0,0 @@ -// Part 5 - Add your import statement to line 2: - - -let kilometersToMars: number = 225000000; -let kilometersToTheMoon: number = 384400; - - -// The variables that are commented out will be moved into the Spacecraft class -// let spaceCraft: string = "Space Shuttle"; -// let speedMph: number = 17500; -// let milesPerKilometer: number = 0.621; - -// This function will also be moved into the Spacecraft class -// function getDaysToLocation(kilometersAway: number): number { -// let milesAway: number = kilometersAway * milesPerKilometer; -// let hours: number = milesAway / speedMph; -// return hours / 24; -// } - -// Part 4 - Define your Spacecraft class here: \ No newline at end of file From 5fcfd912d10e19fee85ab82c735f03787ff966dd Mon Sep 17 00:00:00 2001 From: Jim Flores Date: Mon, 19 Aug 2019 14:19:06 -0500 Subject: [PATCH 02/13] Added print statements to parts 3 - 5. --- exercises/part3.js | 5 +++-- exercises/part3.ts | 7 ++++--- exercises/part4.js | 5 ++++- exercises/part4.ts | 5 ++++- exercises/part5.js | 5 +++-- exercises/part5.ts | 5 +++-- 6 files changed, 21 insertions(+), 11 deletions(-) diff --git a/exercises/part3.js b/exercises/part3.js index cd1acc06..bd00191a 100644 --- a/exercises/part3.js +++ b/exercises/part3.js @@ -5,11 +5,12 @@ var speedMph = 17500; var kilometersToMars = 225000000; var kilometersToTheMoon = 384400; var milesPerKilometer = 0.621; -// Part 3 - Define the 'getDaysToLocation' function here: +// Code the "getDaysToLocation" function here: function getDaysToLocation(kilometersAway) { var milesAway = kilometersAway * milesPerKilometer; var hours = milesAway / speedMph; return hours / 24; } -// Call the function and print the output here: +// Call the function and print the outputs for the Mars trip and the moon trip: console.log(spacecraftName + " would take " + getDaysToLocation(kilometersToMars) + " to get to Mars."); +console.log(spacecraftName + " would take " + getDaysToLocation(kilometersToTheMoon) + " to get to the Moon."); diff --git a/exercises/part3.ts b/exercises/part3.ts index b44eaa74..6d82897e 100644 --- a/exercises/part3.ts +++ b/exercises/part3.ts @@ -7,12 +7,13 @@ let kilometersToMars: number = 225000000; let kilometersToTheMoon: number = 384400; let milesPerKilometer: number = 0.621; -// Part 3 - Define the 'getDaysToLocation' function here: +// Code the "getDaysToLocation" function here: function getDaysToLocation(kilometersAway: number): number { let milesAway: number = kilometersAway * milesPerKilometer; let hours: number = milesAway / speedMph; return hours / 24; } -// Call the function and print the output here: -console.log(`${spacecraftName} would take ${getDaysToLocation(kilometersToMars)} to get to Mars.`); \ No newline at end of file +// Call the function and print the outputs for the Mars trip and the moon trip: +console.log(`${spacecraftName} would take ${getDaysToLocation(kilometersToMars)} to get to Mars.`); +console.log(`${spacecraftName} would take ${getDaysToLocation(kilometersToTheMoon)} to get to the Moon.`); \ No newline at end of file diff --git a/exercises/part4.js b/exercises/part4.js index 6da2e279..df8f5b39 100644 --- a/exercises/part4.js +++ b/exercises/part4.js @@ -1,6 +1,6 @@ var kilometersToMars = 225000000; var kilometersToTheMoon = 384400; -// Part 4 - Define your Spacecraft class here: +// Define your Spacecraft class here: var Spacecraft = /** @class */ (function () { function Spacecraft(name, speedMph) { this.milesPerKilometer = 0.621; @@ -14,5 +14,8 @@ var Spacecraft = /** @class */ (function () { }; return Spacecraft; }()); +// Create an instance of the class here: var spaceShuttle = new Spacecraft('Discovery', 17500); +// Print two outputs - one for the trip to Mars and one for the trip to the moon. console.log(spaceShuttle.name + " would take " + spaceShuttle.getDaysToLocation(kilometersToMars) + " days to get to Mars."); +console.log(spaceShuttle.name + " would take " + spaceShuttle.getDaysToLocation(kilometersToTheMoon) + " days to get to Mars."); diff --git a/exercises/part4.ts b/exercises/part4.ts index 02262a08..d75c14b6 100644 --- a/exercises/part4.ts +++ b/exercises/part4.ts @@ -1,7 +1,7 @@ let kilometersToMars: number = 225000000; let kilometersToTheMoon: number = 384400; -// Part 4 - Define your Spacecraft class here: +// Define your Spacecraft class here: class Spacecraft { milesPerKilometer: number = 0.621; name: string; @@ -20,6 +20,9 @@ class Spacecraft { } +// Create an instance of the class here: let spaceShuttle = new Spacecraft('Discovery', 17500); +// Print two outputs - one for the trip to Mars and one for the trip to the moon. console.log(`${spaceShuttle.name} would take ${spaceShuttle.getDaysToLocation(kilometersToMars)} days to get to Mars.`); +console.log(`${spaceShuttle.name} would take ${spaceShuttle.getDaysToLocation(kilometersToTheMoon)} days to get to Mars.`); diff --git a/exercises/part5.js b/exercises/part5.js index 657b9acb..d0ba3152 100644 --- a/exercises/part5.js +++ b/exercises/part5.js @@ -1,10 +1,9 @@ "use strict"; exports.__esModule = true; -// Part 5 - Add your import statement to line 2: +// Add your import statement to line 2: var SpaceLocation_1 = require("./SpaceLocation"); var kilometersToMars = 225000000; var kilometersToTheMoon = 384400; -// Part 4 - Define your Spacecraft class here: var Spacecraft = /** @class */ (function () { function Spacecraft(name, speedMph) { this.milesPerKilometer = 0.621; @@ -21,6 +20,8 @@ var Spacecraft = /** @class */ (function () { }; return Spacecraft; }()); +// Create an instance of Spacecraft: var spaceShuttle = new Spacecraft('Discovery', 17500); +// Print the output for the trips to Mars and the moon: spaceShuttle.printDaysToLocation(new SpaceLocation_1.SpaceLocation('Mars', kilometersToMars)); spaceShuttle.printDaysToLocation(new SpaceLocation_1.SpaceLocation('the Moon', kilometersToTheMoon)); diff --git a/exercises/part5.ts b/exercises/part5.ts index ebe1b0b3..1327335d 100644 --- a/exercises/part5.ts +++ b/exercises/part5.ts @@ -1,10 +1,9 @@ -// Part 5 - Add your import statement to line 2: +// Add your import statement to line 2: import { SpaceLocation } from './SpaceLocation'; let kilometersToMars: number = 225000000; let kilometersToTheMoon: number = 384400; -// Part 4 - Define your Spacecraft class here: class Spacecraft { milesPerKilometer: number = 0.621; name: string; @@ -26,7 +25,9 @@ class Spacecraft { } } +// Create an instance of Spacecraft: let spaceShuttle = new Spacecraft('Discovery', 17500); +// Print the output for the trips to Mars and the moon: spaceShuttle.printDaysToLocation(new SpaceLocation('Mars', kilometersToMars)); spaceShuttle.printDaysToLocation(new SpaceLocation('the Moon', kilometersToTheMoon)); From b7657794e5f130d80ed854977c3eb6428639aca8 Mon Sep 17 00:00:00 2001 From: Jim Flores Date: Mon, 19 Aug 2019 14:47:27 -0500 Subject: [PATCH 03/13] Updated stuio files. --- studio.ts => studio/studio.ts | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename studio.ts => studio/studio.ts (100%) diff --git a/studio.ts b/studio/studio.ts similarity index 100% rename from studio.ts rename to studio/studio.ts From b4dab230897b4a01175b5d287a4f20ef1bec6d3a Mon Sep 17 00:00:00 2001 From: Jim Flores Date: Mon, 19 Aug 2019 15:32:02 -0500 Subject: [PATCH 04/13] Completed solution for TypeScript studio. --- studio/Astronaut.js | 10 +++++++++ studio/Astronaut.ts | 11 ++++++++++ studio/Cargo.js | 10 +++++++++ studio/Cargo.ts | 11 ++++++++++ studio/Payload.js | 2 ++ studio/Payload.ts | 3 +++ studio/Rocket.js | 43 ++++++++++++++++++++++++++++++++++++++ studio/Rocket.ts | 50 +++++++++++++++++++++++++++++++++++++++++++++ studio/studio.js | 29 ++++++++++++++++++++++++++ studio/studio.ts | 35 +++++++++++++++++++++++++++++++ 10 files changed, 204 insertions(+) create mode 100644 studio/Astronaut.js create mode 100644 studio/Astronaut.ts create mode 100644 studio/Cargo.js create mode 100644 studio/Cargo.ts create mode 100644 studio/Payload.js create mode 100644 studio/Payload.ts create mode 100644 studio/Rocket.js create mode 100644 studio/Rocket.ts create mode 100644 studio/studio.js diff --git a/studio/Astronaut.js b/studio/Astronaut.js new file mode 100644 index 00000000..9fa375e4 --- /dev/null +++ b/studio/Astronaut.js @@ -0,0 +1,10 @@ +"use strict"; +exports.__esModule = true; +var Astronaut = /** @class */ (function () { + function Astronaut(massKg, name) { + this.name = name; + this.massKg = massKg; + } + return Astronaut; +}()); +exports.Astronaut = Astronaut; diff --git a/studio/Astronaut.ts b/studio/Astronaut.ts new file mode 100644 index 00000000..39879eba --- /dev/null +++ b/studio/Astronaut.ts @@ -0,0 +1,11 @@ +import { Payload } from './Payload'; + +export class Astronaut implements Payload { + massKg: number; + name: string; + + constructor (massKg: number, name: string) { + this.name = name; + this.massKg = massKg; + } + } \ No newline at end of file diff --git a/studio/Cargo.js b/studio/Cargo.js new file mode 100644 index 00000000..35162780 --- /dev/null +++ b/studio/Cargo.js @@ -0,0 +1,10 @@ +"use strict"; +exports.__esModule = true; +var Cargo = /** @class */ (function () { + function Cargo(massKg, material) { + this.material = material; + this.massKg = massKg; + } + return Cargo; +}()); +exports.Cargo = Cargo; diff --git a/studio/Cargo.ts b/studio/Cargo.ts new file mode 100644 index 00000000..dc2d895f --- /dev/null +++ b/studio/Cargo.ts @@ -0,0 +1,11 @@ +import { Payload } from './Payload'; + +export class Cargo implements Payload { + massKg: number; + material: string; + + constructor (massKg: number, material: string) { + this.material = material; + this.massKg = massKg; + } +} \ No newline at end of file diff --git a/studio/Payload.js b/studio/Payload.js new file mode 100644 index 00000000..0e345787 --- /dev/null +++ b/studio/Payload.js @@ -0,0 +1,2 @@ +"use strict"; +exports.__esModule = true; diff --git a/studio/Payload.ts b/studio/Payload.ts new file mode 100644 index 00000000..67735819 --- /dev/null +++ b/studio/Payload.ts @@ -0,0 +1,3 @@ +export interface Payload { + massKg: number; + } \ No newline at end of file diff --git a/studio/Rocket.js b/studio/Rocket.js new file mode 100644 index 00000000..671669ea --- /dev/null +++ b/studio/Rocket.js @@ -0,0 +1,43 @@ +"use strict"; +exports.__esModule = true; +var Rocket = /** @class */ (function () { + function Rocket(name, totalCapacityKg) { + this.cargoItems = []; + this.astronauts = []; + this.name = name; + this.totalCapacityKg = totalCapacityKg; + } + Rocket.prototype.sumMass = function (items) { + var sum = 0; + for (var i = 0; i < items.length; i++) { + sum += items[i].massKg; + } + return sum; + }; + Rocket.prototype.currentMassKg = function () { + return this.sumMass(this.astronauts) + this.sumMass(this.cargoItems); + }; + Rocket.prototype.canAdd = function (item) { + return (this.currentMassKg() + item.massKg) <= this.totalCapacityKg; + }; + Rocket.prototype.addCargo = function (cargo) { + if (this.canAdd(cargo)) { + this.cargoItems.push(cargo); + return true; + } + else { + return false; + } + }; + Rocket.prototype.addAstronaut = function (astronaut) { + if (this.canAdd(astronaut)) { + this.astronauts.push(astronaut); + return true; + } + else { + return false; + } + }; + return Rocket; +}()); +exports.Rocket = Rocket; diff --git a/studio/Rocket.ts b/studio/Rocket.ts new file mode 100644 index 00000000..000179c4 --- /dev/null +++ b/studio/Rocket.ts @@ -0,0 +1,50 @@ +import { Payload } from './Payload'; +import { Cargo } from './Cargo'; +import { Astronaut } from './Astronaut'; + +export class Rocket implements Payload { + name: string; + totalCapacityKg: number; + cargoItems: Cargo[] = []; + astronauts: Astronaut[] = []; + massKg: number; + + constructor (name: string, totalCapacityKg: number) { + this.name = name; + this.totalCapacityKg = totalCapacityKg; + } + + sumMass (items: Payload[]): number { + let sum: number = 0; + for (let i=0; i < items.length; i++) { + sum += items[i].massKg; + } + return sum; + } + + currentMassKg (): number { + return this.sumMass(this.astronauts) + this.sumMass(this.cargoItems); + } + + canAdd(item: Payload): boolean { + return (this.currentMassKg() + item.massKg) <= this.totalCapacityKg; + } + + addCargo(cargo: Cargo): boolean { + if (this.canAdd(cargo)) { + this.cargoItems.push(cargo); + return true; + } else { + return false; + } + } + + addAstronaut(astronaut: Astronaut): boolean { + if (this.canAdd(astronaut)) { + this.astronauts.push(astronaut); + return true; + } else { + return false; + } + } +} \ No newline at end of file diff --git a/studio/studio.js b/studio/studio.js new file mode 100644 index 00000000..af40bbf1 --- /dev/null +++ b/studio/studio.js @@ -0,0 +1,29 @@ +"use strict"; +// Instructions are published in the online book. The URL is: +// https://education.launchcode.org/intro-to-professional-web-dev/chapters/typescript/studio.html +exports.__esModule = true; +var Astronaut_1 = require("./Astronaut"); +var Cargo_1 = require("./Cargo"); +var Rocket_1 = require("./Rocket"); +var falcon9 = new Rocket_1.Rocket('Falcon 9', 7500); +var astronauts = [ + new Astronaut_1.Astronaut(75, 'Mae'), + new Astronaut_1.Astronaut(81, 'Sally'), + new Astronaut_1.Astronaut(99, 'Charles') +]; +for (var i = 0; i < astronauts.length; i++) { + var astronaut = astronauts[i]; + console.log(astronaut.name, falcon9.addAstronaut(astronaut)); +} +var cargo = [ + new Cargo_1.Cargo(3107.39, "Satellite"), + new Cargo_1.Cargo(1000.39, "Space Probe"), + new Cargo_1.Cargo(753, "Water"), + new Cargo_1.Cargo(541, "Food"), + new Cargo_1.Cargo(2107.39, "Tesla Roadster"), +]; +for (var i = 0; i < cargo.length; i++) { + var c = cargo[i]; + console.log(c.material, falcon9.addCargo(c)); +} +console.log("Final cargo and astronaut mass: " + falcon9.currentMassKg() + " kg."); diff --git a/studio/studio.ts b/studio/studio.ts index e69de29b..023ad7ed 100644 --- a/studio/studio.ts +++ b/studio/studio.ts @@ -0,0 +1,35 @@ +// Instructions are published in the online book. The URL is: +// https://education.launchcode.org/intro-to-professional-web-dev/chapters/typescript/studio.html + +import { Astronaut } from './Astronaut'; +import { Cargo } from './Cargo'; +import { Rocket } from './Rocket'; + +let falcon9: Rocket = new Rocket('Falcon 9', 7500); + +let astronauts: Astronaut[] = [ + new Astronaut(75, 'Mae'), + new Astronaut(81, 'Sally'), + new Astronaut(99, 'Charles') +]; + +for (let i =0; i < astronauts.length; i++) { + let astronaut = astronauts[i]; + console.log(astronaut.name, falcon9.addAstronaut(astronaut)); +} + +let cargo: Cargo[] = [ + new Cargo(3107.39, "Satellite"), + new Cargo(1000.39, "Space Probe"), + new Cargo(753, "Water"), + new Cargo(541, "Food"), + new Cargo(2107.39, "Tesla Roadster"), +]; + +for (let i =0; i < cargo.length; i++) { + let c = cargo[i]; + console.log(c.material, falcon9.addCargo(c)); +} + +console.log(`Final cargo and astronaut mass: ${falcon9.currentMassKg()} kg.`); + From 44e2a5358a2691fb35d169c22efde88f8b58dc56 Mon Sep 17 00:00:00 2001 From: Jim Flores Date: Mon, 19 Aug 2019 15:47:52 -0500 Subject: [PATCH 05/13] Renamed studio.ts file to index.ts. --- studio/{studio.js => index.js} | 0 studio/{studio.ts => index.ts} | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename studio/{studio.js => index.js} (100%) rename studio/{studio.ts => index.ts} (100%) diff --git a/studio/studio.js b/studio/index.js similarity index 100% rename from studio/studio.js rename to studio/index.js diff --git a/studio/studio.ts b/studio/index.ts similarity index 100% rename from studio/studio.ts rename to studio/index.ts From 74c90b448975ae80ce9b53c05c9153e412d700b2 Mon Sep 17 00:00:00 2001 From: Jim Flores Date: Tue, 20 Aug 2019 14:45:16 -0500 Subject: [PATCH 06/13] Fixed typo in Payload.ts file. --- studio/Payload.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/studio/Payload.ts b/studio/Payload.ts index 67735819..0b242a1d 100644 --- a/studio/Payload.ts +++ b/studio/Payload.ts @@ -1,3 +1,3 @@ export interface Payload { massKg: number; - } \ No newline at end of file +} \ No newline at end of file From 100717b186fd604b37bf91371811da8a348776a6 Mon Sep 17 00:00:00 2001 From: Jim Flores Date: Tue, 20 Aug 2019 16:04:06 -0500 Subject: [PATCH 07/13] Updated code to print more detailed output. --- studio/index.js | 18 ++++++++++++++++-- studio/index.ts | 20 ++++++++++++++++---- 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/studio/index.js b/studio/index.js index af40bbf1..591fd539 100644 --- a/studio/index.js +++ b/studio/index.js @@ -13,7 +13,14 @@ var astronauts = [ ]; for (var i = 0; i < astronauts.length; i++) { var astronaut = astronauts[i]; - console.log(astronaut.name, falcon9.addAstronaut(astronaut)); + var status_1 = ''; + if (falcon9.addAstronaut(astronaut)) { + status_1 = "On board"; + } + else { + status_1 = "Not on board"; + } + console.log(astronaut.name + ": " + status_1); } var cargo = [ new Cargo_1.Cargo(3107.39, "Satellite"), @@ -24,6 +31,13 @@ var cargo = [ ]; for (var i = 0; i < cargo.length; i++) { var c = cargo[i]; - console.log(c.material, falcon9.addCargo(c)); + var loaded = ''; + if (falcon9.addCargo(c)) { + loaded = "Loaded"; + } + else { + loaded = "Not loaded"; + } + console.log(c.material + ": " + loaded); } console.log("Final cargo and astronaut mass: " + falcon9.currentMassKg() + " kg."); diff --git a/studio/index.ts b/studio/index.ts index 023ad7ed..c7e3bff3 100644 --- a/studio/index.ts +++ b/studio/index.ts @@ -13,9 +13,15 @@ let astronauts: Astronaut[] = [ new Astronaut(99, 'Charles') ]; -for (let i =0; i < astronauts.length; i++) { +for (let i = 0; i < astronauts.length; i++) { let astronaut = astronauts[i]; - console.log(astronaut.name, falcon9.addAstronaut(astronaut)); + let status = ''; + if (falcon9.addAstronaut(astronaut)) { + status = "On board"; + } else { + status = "Not on board"; + } + console.log(`${astronaut.name}: ${status}`); } let cargo: Cargo[] = [ @@ -26,9 +32,15 @@ let cargo: Cargo[] = [ new Cargo(2107.39, "Tesla Roadster"), ]; -for (let i =0; i < cargo.length; i++) { +for (let i = 0; i < cargo.length; i++) { let c = cargo[i]; - console.log(c.material, falcon9.addCargo(c)); + let loaded = ''; + if (falcon9.addCargo(c)) { + loaded = "Loaded" + } else { + loaded = "Not loaded" + } + console.log(`${c.material}: ${loaded}`); } console.log(`Final cargo and astronaut mass: ${falcon9.currentMassKg()} kg.`); From e4d1d45cbf1486b11c86c4ad81f638767e3b00e0 Mon Sep 17 00:00:00 2001 From: jimflores Date: Wed, 5 Feb 2020 14:13:39 -0600 Subject: [PATCH 08/13] Initial commit. --- .vscode/settings.json | 5 +++++ exercises/parts1-5.ts | 0 2 files changed, 5 insertions(+) create mode 100644 .vscode/settings.json create mode 100644 exercises/parts1-5.ts diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 00000000..90a54399 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "cSpell.ignoreWords": [ + "esnext" + ] +} \ No newline at end of file diff --git a/exercises/parts1-5.ts b/exercises/parts1-5.ts new file mode 100644 index 00000000..e69de29b From de3aa94b86a23145314b2e530ca3d09342c327f9 Mon Sep 17 00:00:00 2001 From: jimflores Date: Wed, 5 Feb 2020 14:24:25 -0600 Subject: [PATCH 09/13] Refactored solution to use only one .ts file. --- exercises/part1-2.js | 14 --------- exercises/part1-2.ts | 17 ---------- exercises/part3.js | 16 ---------- exercises/part3.ts | 19 ----------- exercises/part4.js | 21 ------------- exercises/part4.ts | 28 ----------------- exercises/part5.ts | 33 ------------------- exercises/{part5.js => parts1-5.js} | 13 ++++++-- exercises/parts1-5.ts | 49 +++++++++++++++++++++++++++++ 9 files changed, 59 insertions(+), 151 deletions(-) delete mode 100644 exercises/part1-2.js delete mode 100644 exercises/part1-2.ts delete mode 100644 exercises/part3.js delete mode 100644 exercises/part3.ts delete mode 100644 exercises/part4.js delete mode 100644 exercises/part4.ts delete mode 100644 exercises/part5.ts rename exercises/{part5.js => parts1-5.js} (67%) diff --git a/exercises/part1-2.js b/exercises/part1-2.js deleted file mode 100644 index f75c7079..00000000 --- a/exercises/part1-2.js +++ /dev/null @@ -1,14 +0,0 @@ -// URL for the instructions: -// https://education.launchcode.org/intro-to-professional-web-dev/chapters/typescript/exercises.html -// Part 1: Add the 5 variables here -var spacecraftName = "Discovery"; -var speedMph = 17500; -var kilometersToMars = 225000000; -var kilometersToTheMoon = 384400; -var milesPerKilometer = 0.621; -// Code part 2 here: -var milesToMars = kilometersToMars * milesPerKilometer; -var hoursToMars = milesToMars / speedMph; -var daysToMars = hoursToMars / 24; -// Code the output statement here (use a template literal): -console.log(spacecraftName + " would take " + daysToMars + " to get to Mars."); diff --git a/exercises/part1-2.ts b/exercises/part1-2.ts deleted file mode 100644 index b687bb36..00000000 --- a/exercises/part1-2.ts +++ /dev/null @@ -1,17 +0,0 @@ -// URL for the instructions: -// https://education.launchcode.org/intro-to-professional-web-dev/chapters/typescript/exercises.html - -// Part 1: Add the 5 variables here -let spacecraftName: string = "Discovery"; -let speedMph: number = 17500; -let kilometersToMars: number = 225000000; -let kilometersToTheMoon: number = 384400; -let milesPerKilometer: number = 0.621; - -// Code part 2 here: -let milesToMars: number = kilometersToMars*milesPerKilometer; -let hoursToMars: number = milesToMars/speedMph; -let daysToMars: number = hoursToMars/24; - -// Code the output statement here (use a template literal): -console.log(`${spacecraftName} would take ${daysToMars} to get to Mars.`); \ No newline at end of file diff --git a/exercises/part3.js b/exercises/part3.js deleted file mode 100644 index bd00191a..00000000 --- a/exercises/part3.js +++ /dev/null @@ -1,16 +0,0 @@ -// URL for the instructions: -// https://education.launchcode.org/intro-to-professional-web-dev/chapters/typescript/exercises.html -var spacecraftName = "Discovery"; -var speedMph = 17500; -var kilometersToMars = 225000000; -var kilometersToTheMoon = 384400; -var milesPerKilometer = 0.621; -// Code the "getDaysToLocation" function here: -function getDaysToLocation(kilometersAway) { - var milesAway = kilometersAway * milesPerKilometer; - var hours = milesAway / speedMph; - return hours / 24; -} -// Call the function and print the outputs for the Mars trip and the moon trip: -console.log(spacecraftName + " would take " + getDaysToLocation(kilometersToMars) + " to get to Mars."); -console.log(spacecraftName + " would take " + getDaysToLocation(kilometersToTheMoon) + " to get to the Moon."); diff --git a/exercises/part3.ts b/exercises/part3.ts deleted file mode 100644 index 6d82897e..00000000 --- a/exercises/part3.ts +++ /dev/null @@ -1,19 +0,0 @@ -// URL for the instructions: -// https://education.launchcode.org/intro-to-professional-web-dev/chapters/typescript/exercises.html - -let spacecraftName: string = "Discovery"; -let speedMph: number = 17500; -let kilometersToMars: number = 225000000; -let kilometersToTheMoon: number = 384400; -let milesPerKilometer: number = 0.621; - -// Code the "getDaysToLocation" function here: -function getDaysToLocation(kilometersAway: number): number { - let milesAway: number = kilometersAway * milesPerKilometer; - let hours: number = milesAway / speedMph; - return hours / 24; -} - -// Call the function and print the outputs for the Mars trip and the moon trip: -console.log(`${spacecraftName} would take ${getDaysToLocation(kilometersToMars)} to get to Mars.`); -console.log(`${spacecraftName} would take ${getDaysToLocation(kilometersToTheMoon)} to get to the Moon.`); \ No newline at end of file diff --git a/exercises/part4.js b/exercises/part4.js deleted file mode 100644 index df8f5b39..00000000 --- a/exercises/part4.js +++ /dev/null @@ -1,21 +0,0 @@ -var kilometersToMars = 225000000; -var kilometersToTheMoon = 384400; -// Define your Spacecraft class here: -var Spacecraft = /** @class */ (function () { - function Spacecraft(name, speedMph) { - this.milesPerKilometer = 0.621; - this.name = name; - this.speedMph = speedMph; - } - Spacecraft.prototype.getDaysToLocation = function (kilometersAway) { - var milesAway = kilometersAway * this.milesPerKilometer; - var hours = milesAway / this.speedMph; - return hours / 24; - }; - return Spacecraft; -}()); -// Create an instance of the class here: -var spaceShuttle = new Spacecraft('Discovery', 17500); -// Print two outputs - one for the trip to Mars and one for the trip to the moon. -console.log(spaceShuttle.name + " would take " + spaceShuttle.getDaysToLocation(kilometersToMars) + " days to get to Mars."); -console.log(spaceShuttle.name + " would take " + spaceShuttle.getDaysToLocation(kilometersToTheMoon) + " days to get to Mars."); diff --git a/exercises/part4.ts b/exercises/part4.ts deleted file mode 100644 index d75c14b6..00000000 --- a/exercises/part4.ts +++ /dev/null @@ -1,28 +0,0 @@ -let kilometersToMars: number = 225000000; -let kilometersToTheMoon: number = 384400; - -// Define your Spacecraft class here: -class Spacecraft { - milesPerKilometer: number = 0.621; - name: string; - speedMph: number; - - constructor (name: string, speedMph: number) { - this.name = name; - this.speedMph = speedMph; - } - - getDaysToLocation(kilometersAway: number): number { - let milesAway: number = kilometersAway * this.milesPerKilometer; - let hours: number = milesAway / this.speedMph; - return hours / 24; - } - -} - -// Create an instance of the class here: -let spaceShuttle = new Spacecraft('Discovery', 17500); - -// Print two outputs - one for the trip to Mars and one for the trip to the moon. -console.log(`${spaceShuttle.name} would take ${spaceShuttle.getDaysToLocation(kilometersToMars)} days to get to Mars.`); -console.log(`${spaceShuttle.name} would take ${spaceShuttle.getDaysToLocation(kilometersToTheMoon)} days to get to Mars.`); diff --git a/exercises/part5.ts b/exercises/part5.ts deleted file mode 100644 index 1327335d..00000000 --- a/exercises/part5.ts +++ /dev/null @@ -1,33 +0,0 @@ -// Add your import statement to line 2: -import { SpaceLocation } from './SpaceLocation'; - -let kilometersToMars: number = 225000000; -let kilometersToTheMoon: number = 384400; - -class Spacecraft { - milesPerKilometer: number = 0.621; - name: string; - speedMph: number; - - constructor (name: string, speedMph: number) { - this.name = name; - this.speedMph = speedMph; - } - - getDaysToLocation(kilometersAway: number): number { - let milesAway: number = kilometersAway * this.milesPerKilometer; - let hours: number = milesAway / this.speedMph; - return hours / 24; - } - - printDaysToLocation(location: SpaceLocation) { - console.log(`${this.name} would take ${this.getDaysToLocation(location.kilometersAway)} days to get to ${location.name}.`); - } -} - -// Create an instance of Spacecraft: -let spaceShuttle = new Spacecraft('Discovery', 17500); - -// Print the output for the trips to Mars and the moon: -spaceShuttle.printDaysToLocation(new SpaceLocation('Mars', kilometersToMars)); -spaceShuttle.printDaysToLocation(new SpaceLocation('the Moon', kilometersToTheMoon)); diff --git a/exercises/part5.js b/exercises/parts1-5.js similarity index 67% rename from exercises/part5.js rename to exercises/parts1-5.js index d0ba3152..a9c0b6af 100644 --- a/exercises/part5.js +++ b/exercises/parts1-5.js @@ -1,9 +1,15 @@ "use strict"; +// URL for the instructions: +// https://education.launchcode.org/intro-to-professional-web-dev/chapters/typescript/exercises.html exports.__esModule = true; -// Add your import statement to line 2: +// Part 5: Import statement. var SpaceLocation_1 = require("./SpaceLocation"); +// Part 1: Remaining variables. var kilometersToMars = 225000000; var kilometersToTheMoon = 384400; +// Part 2: Content moved into class. Output statements updated. +// Part 3: Content moved into class. Output statements updated. +// Part 4: Define your Spacecraft class: var Spacecraft = /** @class */ (function () { function Spacecraft(name, speedMph) { this.milesPerKilometer = 0.621; @@ -20,8 +26,9 @@ var Spacecraft = /** @class */ (function () { }; return Spacecraft; }()); -// Create an instance of Spacecraft: +// Create an instance of the class here: var spaceShuttle = new Spacecraft('Discovery', 17500); -// Print the output for the trips to Mars and the moon: +// Part 5: Add the required import statement BEFORE the part 1 concent. +// Paste in the code from step 6 here: spaceShuttle.printDaysToLocation(new SpaceLocation_1.SpaceLocation('Mars', kilometersToMars)); spaceShuttle.printDaysToLocation(new SpaceLocation_1.SpaceLocation('the Moon', kilometersToTheMoon)); diff --git a/exercises/parts1-5.ts b/exercises/parts1-5.ts index e69de29b..ef2be1d9 100644 --- a/exercises/parts1-5.ts +++ b/exercises/parts1-5.ts @@ -0,0 +1,49 @@ +// URL for the instructions: +// https://education.launchcode.org/intro-to-professional-web-dev/chapters/typescript/exercises.html + +// Part 5: Import statement. +import { SpaceLocation } from './SpaceLocation'; + +// Part 1: Remaining variables. +let kilometersToMars: number = 225000000; +let kilometersToTheMoon: number = 384400; + +// Part 2: Content moved into class. Output statements updated. + + +// Part 3: Content moved into class. Output statements updated. + + +// Part 4: Define your Spacecraft class: + +class Spacecraft { + milesPerKilometer: number = 0.621; + name: string; + speedMph: number; + + constructor (name: string, speedMph: number) { + this.name = name; + this.speedMph = speedMph; + } + + getDaysToLocation(kilometersAway: number): number { + let milesAway: number = kilometersAway * this.milesPerKilometer; + let hours: number = milesAway / this.speedMph; + return hours / 24; + } + + printDaysToLocation(location: SpaceLocation) { + console.log(`${this.name} would take ${this.getDaysToLocation(location.kilometersAway)} days to get to ${location.name}.`); + } +} + +// Create an instance of the class here: +let spaceShuttle = new Spacecraft('Discovery', 17500); + + +// Part 5: Add the required import statement BEFORE the part 1 concent. + + +// Paste in the code from step 6 here: +spaceShuttle.printDaysToLocation(new SpaceLocation('Mars', kilometersToMars)); +spaceShuttle.printDaysToLocation(new SpaceLocation('the Moon', kilometersToTheMoon)); \ No newline at end of file From ddace55608046b2e1ec1c813f73c79d704aeb149 Mon Sep 17 00:00:00 2001 From: jimflores Date: Wed, 5 Feb 2020 14:27:41 -0600 Subject: [PATCH 10/13] Final edits to revised solution code. --- exercises/parts1-5.js | 5 ++--- exercises/parts1-5.ts | 7 ++----- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/exercises/parts1-5.js b/exercises/parts1-5.js index a9c0b6af..77e1f7e8 100644 --- a/exercises/parts1-5.js +++ b/exercises/parts1-5.js @@ -27,8 +27,7 @@ var Spacecraft = /** @class */ (function () { return Spacecraft; }()); // Create an instance of the class here: -var spaceShuttle = new Spacecraft('Discovery', 17500); -// Part 5: Add the required import statement BEFORE the part 1 concent. -// Paste in the code from step 6 here: +var spaceShuttle = new Spacecraft('Determination', 17500); +// Part 5: Paste in the code from step 6 here: spaceShuttle.printDaysToLocation(new SpaceLocation_1.SpaceLocation('Mars', kilometersToMars)); spaceShuttle.printDaysToLocation(new SpaceLocation_1.SpaceLocation('the Moon', kilometersToTheMoon)); diff --git a/exercises/parts1-5.ts b/exercises/parts1-5.ts index ef2be1d9..185a2b6e 100644 --- a/exercises/parts1-5.ts +++ b/exercises/parts1-5.ts @@ -38,12 +38,9 @@ class Spacecraft { } // Create an instance of the class here: -let spaceShuttle = new Spacecraft('Discovery', 17500); +let spaceShuttle = new Spacecraft('Determination', 17500); -// Part 5: Add the required import statement BEFORE the part 1 concent. - - -// Paste in the code from step 6 here: +// Part 5: Paste in the code from step 6 here: spaceShuttle.printDaysToLocation(new SpaceLocation('Mars', kilometersToMars)); spaceShuttle.printDaysToLocation(new SpaceLocation('the Moon', kilometersToTheMoon)); \ No newline at end of file From 71fbd555555fac0a06239cdaf9110b40cbe9462d Mon Sep 17 00:00:00 2001 From: jimflores Date: Wed, 5 Feb 2020 15:58:28 -0600 Subject: [PATCH 11/13] Added gitignore file. --- .gitignore | 1 + 1 file changed, 1 insertion(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..dbe9c82b --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.vscode/ \ No newline at end of file From 33bc75f61a2948fb21dfc19bc05940c269ce8a4a Mon Sep 17 00:00:00 2001 From: ianmottert <84425497+ianmottert@users.noreply.github.com> Date: Thu, 29 Jul 2021 17:34:15 -0500 Subject: [PATCH 12/13] Add files via upload --- exercises/SpaceLocation.js | 20 ++++----- exercises/SpaceLocation.ts | 16 +++---- exercises/parts1-5.js | 66 ++++++++++++++-------------- exercises/parts1-5.ts | 90 +++++++++++++++++++------------------- exercises/tsconfig.json | 32 +++++++------- 5 files changed, 112 insertions(+), 112 deletions(-) diff --git a/exercises/SpaceLocation.js b/exercises/SpaceLocation.js index f80d96d3..3977adb7 100644 --- a/exercises/SpaceLocation.js +++ b/exercises/SpaceLocation.js @@ -1,10 +1,10 @@ -"use strict"; -exports.__esModule = true; -var SpaceLocation = /** @class */ (function () { - function SpaceLocation(name, kilometersAway) { - this.name = name; - this.kilometersAway = kilometersAway; - } - return SpaceLocation; -}()); -exports.SpaceLocation = SpaceLocation; +"use strict"; +exports.__esModule = true; +var SpaceLocation = /** @class */ (function () { + function SpaceLocation(name, kilometersAway) { + this.name = name; + this.kilometersAway = kilometersAway; + } + return SpaceLocation; +}()); +exports.SpaceLocation = SpaceLocation; diff --git a/exercises/SpaceLocation.ts b/exercises/SpaceLocation.ts index 8c83fe40..fe5fb77f 100644 --- a/exercises/SpaceLocation.ts +++ b/exercises/SpaceLocation.ts @@ -1,9 +1,9 @@ -export class SpaceLocation { - kilometersAway: number; - name: string; - - constructor(name: string, kilometersAway: number) { - this.name = name; - this.kilometersAway = kilometersAway; - } +export class SpaceLocation { + kilometersAway: number; + name: string; + + constructor(name: string, kilometersAway: number) { + this.name = name; + this.kilometersAway = kilometersAway; + } } \ No newline at end of file diff --git a/exercises/parts1-5.js b/exercises/parts1-5.js index 77e1f7e8..ecc38af9 100644 --- a/exercises/parts1-5.js +++ b/exercises/parts1-5.js @@ -1,33 +1,33 @@ -"use strict"; -// URL for the instructions: -// https://education.launchcode.org/intro-to-professional-web-dev/chapters/typescript/exercises.html -exports.__esModule = true; -// Part 5: Import statement. -var SpaceLocation_1 = require("./SpaceLocation"); -// Part 1: Remaining variables. -var kilometersToMars = 225000000; -var kilometersToTheMoon = 384400; -// Part 2: Content moved into class. Output statements updated. -// Part 3: Content moved into class. Output statements updated. -// Part 4: Define your Spacecraft class: -var Spacecraft = /** @class */ (function () { - function Spacecraft(name, speedMph) { - this.milesPerKilometer = 0.621; - this.name = name; - this.speedMph = speedMph; - } - Spacecraft.prototype.getDaysToLocation = function (kilometersAway) { - var milesAway = kilometersAway * this.milesPerKilometer; - var hours = milesAway / this.speedMph; - return hours / 24; - }; - Spacecraft.prototype.printDaysToLocation = function (location) { - console.log(this.name + " would take " + this.getDaysToLocation(location.kilometersAway) + " days to get to " + location.name + "."); - }; - return Spacecraft; -}()); -// Create an instance of the class here: -var spaceShuttle = new Spacecraft('Determination', 17500); -// Part 5: Paste in the code from step 6 here: -spaceShuttle.printDaysToLocation(new SpaceLocation_1.SpaceLocation('Mars', kilometersToMars)); -spaceShuttle.printDaysToLocation(new SpaceLocation_1.SpaceLocation('the Moon', kilometersToTheMoon)); +"use strict"; +// URL for the instructions: +// https://education.launchcode.org/intro-to-professional-web-dev/chapters/typescript/exercises.html +exports.__esModule = true; +// Part 5: Import statement. +var SpaceLocation_1 = require("./SpaceLocation"); +// Part 1: Remaining variables. +var kilometersToMars = 225000000; +var kilometersToTheMoon = 384400; +// Part 2: Content moved into class. Output statements updated. +// Part 3: Content moved into class. Output statements updated. +// Part 4: Define your Spacecraft class: +var Spacecraft = /** @class */ (function () { + function Spacecraft(name, speedMph) { + this.milesPerKilometer = 0.621; + this.name = name; + this.speedMph = speedMph; + } + Spacecraft.prototype.getDaysToLocation = function (kilometersAway) { + var milesAway = kilometersAway * this.milesPerKilometer; + var hours = milesAway / this.speedMph; + return hours / 24; + }; + Spacecraft.prototype.printDaysToLocation = function (location) { + console.log(this.name + " would take " + this.getDaysToLocation(location.kilometersAway) + " days to get to " + location.name + "."); + }; + return Spacecraft; +}()); +// Create an instance of the class here: +var spaceShuttle = new Spacecraft('Determination', 17500); +// Part 5: Paste in the code from step 6 here: +spaceShuttle.printDaysToLocation(new SpaceLocation_1.SpaceLocation('Mars', kilometersToMars)); +spaceShuttle.printDaysToLocation(new SpaceLocation_1.SpaceLocation('the Moon', kilometersToTheMoon)); diff --git a/exercises/parts1-5.ts b/exercises/parts1-5.ts index 185a2b6e..6b1141f7 100644 --- a/exercises/parts1-5.ts +++ b/exercises/parts1-5.ts @@ -1,46 +1,46 @@ -// URL for the instructions: -// https://education.launchcode.org/intro-to-professional-web-dev/chapters/typescript/exercises.html - -// Part 5: Import statement. -import { SpaceLocation } from './SpaceLocation'; - -// Part 1: Remaining variables. -let kilometersToMars: number = 225000000; -let kilometersToTheMoon: number = 384400; - -// Part 2: Content moved into class. Output statements updated. - - -// Part 3: Content moved into class. Output statements updated. - - -// Part 4: Define your Spacecraft class: - -class Spacecraft { - milesPerKilometer: number = 0.621; - name: string; - speedMph: number; - - constructor (name: string, speedMph: number) { - this.name = name; - this.speedMph = speedMph; - } - - getDaysToLocation(kilometersAway: number): number { - let milesAway: number = kilometersAway * this.milesPerKilometer; - let hours: number = milesAway / this.speedMph; - return hours / 24; - } - - printDaysToLocation(location: SpaceLocation) { - console.log(`${this.name} would take ${this.getDaysToLocation(location.kilometersAway)} days to get to ${location.name}.`); - } -} - -// Create an instance of the class here: -let spaceShuttle = new Spacecraft('Determination', 17500); - - -// Part 5: Paste in the code from step 6 here: -spaceShuttle.printDaysToLocation(new SpaceLocation('Mars', kilometersToMars)); +// URL for the instructions: +// https://education.launchcode.org/intro-to-professional-web-dev/chapters/typescript/exercises.html + +// Part 5: Import statement. +import { SpaceLocation } from './SpaceLocation'; + +// Part 1: Remaining variables. +let kilometersToMars: number = 225000000; +let kilometersToTheMoon: number = 384400; + +// Part 2: Content moved into class. Output statements updated. + + +// Part 3: Content moved into class. Output statements updated. + + +// Part 4: Define your Spacecraft class: + +class Spacecraft { + milesPerKilometer: number = 0.621; + name: string; + speedMph: number; + + constructor (name: string, speedMph: number) { + this.name = name; + this.speedMph = speedMph; + } + + getDaysToLocation(kilometersAway: number): number { + let milesAway: number = kilometersAway * this.milesPerKilometer; + let hours: number = milesAway / this.speedMph; + return hours / 24; + } + + printDaysToLocation(location: SpaceLocation) { + console.log(`${this.name} would take ${this.getDaysToLocation(location.kilometersAway)} days to get to ${location.name}.`); + } +} + +// Create an instance of the class here: +let spaceShuttle = new Spacecraft('Determination', 17500); + + +// Part 5: Paste in the code from step 6 here: +spaceShuttle.printDaysToLocation(new SpaceLocation('Mars', kilometersToMars)); spaceShuttle.printDaysToLocation(new SpaceLocation('the Moon', kilometersToTheMoon)); \ No newline at end of file diff --git a/exercises/tsconfig.json b/exercises/tsconfig.json index 51f08b09..a4f9fa4a 100644 --- a/exercises/tsconfig.json +++ b/exercises/tsconfig.json @@ -1,17 +1,17 @@ -{ - "compilerOptions": { - "target": "es6", - "lib": ["esnext", "dom"], - "module": "commonjs", - "moduleResolution": "node", - "strict": true, - "jsx": "react", - "allowJs": true, - "sourceMap": true, - "inlineSources": true, - "types": ["node"], - "allowSyntheticDefaultImports": true, - "experimentalDecorators": true - } - } +{ + "compilerOptions": { + "target": "es6", + "lib": ["esnext", "dom"], + "module": "commonjs", + "moduleResolution": "node", + "strict": true, + "jsx": "react", + "allowJs": true, + "sourceMap": true, + "inlineSources": true, + "types": ["node"], + "allowSyntheticDefaultImports": true, + "experimentalDecorators": true + } + } \ No newline at end of file From 7f668146d2825cca190df9328ff65e0919d41885 Mon Sep 17 00:00:00 2001 From: ianmottert <84425497+ianmottert@users.noreply.github.com> Date: Thu, 29 Jul 2021 20:13:58 -0500 Subject: [PATCH 13/13] Add files via upload --- studio/Astronaut.js | 20 ++++----- studio/Astronaut.ts | 20 ++++----- studio/Cargo.js | 20 ++++----- studio/Cargo.ts | 20 ++++----- studio/Payload.js | 4 +- studio/Payload.ts | 4 +- studio/Rocket.js | 86 +++++++++++++++++++-------------------- studio/Rocket.ts | 98 ++++++++++++++++++++++----------------------- studio/index.js | 86 +++++++++++++++++++-------------------- studio/index.ts | 94 +++++++++++++++++++++---------------------- 10 files changed, 226 insertions(+), 226 deletions(-) diff --git a/studio/Astronaut.js b/studio/Astronaut.js index 9fa375e4..34ff9e73 100644 --- a/studio/Astronaut.js +++ b/studio/Astronaut.js @@ -1,10 +1,10 @@ -"use strict"; -exports.__esModule = true; -var Astronaut = /** @class */ (function () { - function Astronaut(massKg, name) { - this.name = name; - this.massKg = massKg; - } - return Astronaut; -}()); -exports.Astronaut = Astronaut; +"use strict"; +exports.__esModule = true; +var Astronaut = /** @class */ (function () { + function Astronaut(massKg, name) { + this.name = name; + this.massKg = massKg; + } + return Astronaut; +}()); +exports.Astronaut = Astronaut; diff --git a/studio/Astronaut.ts b/studio/Astronaut.ts index 39879eba..f7f6b8fc 100644 --- a/studio/Astronaut.ts +++ b/studio/Astronaut.ts @@ -1,11 +1,11 @@ -import { Payload } from './Payload'; - -export class Astronaut implements Payload { - massKg: number; - name: string; - - constructor (massKg: number, name: string) { - this.name = name; - this.massKg = massKg; - } +import { Payload } from './Payload'; + +export class Astronaut implements Payload { + massKg: number; + name: string; + + constructor (massKg: number, name: string) { + this.name = name; + this.massKg = massKg; + } } \ No newline at end of file diff --git a/studio/Cargo.js b/studio/Cargo.js index 35162780..4f627519 100644 --- a/studio/Cargo.js +++ b/studio/Cargo.js @@ -1,10 +1,10 @@ -"use strict"; -exports.__esModule = true; -var Cargo = /** @class */ (function () { - function Cargo(massKg, material) { - this.material = material; - this.massKg = massKg; - } - return Cargo; -}()); -exports.Cargo = Cargo; +"use strict"; +exports.__esModule = true; +var Cargo = /** @class */ (function () { + function Cargo(massKg, material) { + this.material = material; + this.massKg = massKg; + } + return Cargo; +}()); +exports.Cargo = Cargo; diff --git a/studio/Cargo.ts b/studio/Cargo.ts index dc2d895f..41aa9968 100644 --- a/studio/Cargo.ts +++ b/studio/Cargo.ts @@ -1,11 +1,11 @@ -import { Payload } from './Payload'; - -export class Cargo implements Payload { - massKg: number; - material: string; - - constructor (massKg: number, material: string) { - this.material = material; - this.massKg = massKg; - } +import { Payload } from './Payload'; + +export class Cargo implements Payload { + massKg: number; + material: string; + + constructor (massKg: number, material: string) { + this.material = material; + this.massKg = massKg; + } } \ No newline at end of file diff --git a/studio/Payload.js b/studio/Payload.js index 0e345787..64cbe53a 100644 --- a/studio/Payload.js +++ b/studio/Payload.js @@ -1,2 +1,2 @@ -"use strict"; -exports.__esModule = true; +"use strict"; +exports.__esModule = true; diff --git a/studio/Payload.ts b/studio/Payload.ts index 0b242a1d..84a2430d 100644 --- a/studio/Payload.ts +++ b/studio/Payload.ts @@ -1,3 +1,3 @@ -export interface Payload { - massKg: number; +export interface Payload { + massKg: number; } \ No newline at end of file diff --git a/studio/Rocket.js b/studio/Rocket.js index 671669ea..ae8c1c7e 100644 --- a/studio/Rocket.js +++ b/studio/Rocket.js @@ -1,43 +1,43 @@ -"use strict"; -exports.__esModule = true; -var Rocket = /** @class */ (function () { - function Rocket(name, totalCapacityKg) { - this.cargoItems = []; - this.astronauts = []; - this.name = name; - this.totalCapacityKg = totalCapacityKg; - } - Rocket.prototype.sumMass = function (items) { - var sum = 0; - for (var i = 0; i < items.length; i++) { - sum += items[i].massKg; - } - return sum; - }; - Rocket.prototype.currentMassKg = function () { - return this.sumMass(this.astronauts) + this.sumMass(this.cargoItems); - }; - Rocket.prototype.canAdd = function (item) { - return (this.currentMassKg() + item.massKg) <= this.totalCapacityKg; - }; - Rocket.prototype.addCargo = function (cargo) { - if (this.canAdd(cargo)) { - this.cargoItems.push(cargo); - return true; - } - else { - return false; - } - }; - Rocket.prototype.addAstronaut = function (astronaut) { - if (this.canAdd(astronaut)) { - this.astronauts.push(astronaut); - return true; - } - else { - return false; - } - }; - return Rocket; -}()); -exports.Rocket = Rocket; +"use strict"; +exports.__esModule = true; +var Rocket = /** @class */ (function () { + function Rocket(name, totalCapacityKg) { + this.cargoItems = []; + this.astronauts = []; + this.name = name; + this.totalCapacityKg = totalCapacityKg; + } + Rocket.prototype.sumMass = function (items) { + var sum = 0; + for (var i = 0; i < items.length; i++) { + sum += items[i].massKg; + } + return sum; + }; + Rocket.prototype.currentMassKg = function () { + return this.sumMass(this.astronauts) + this.sumMass(this.cargoItems); + }; + Rocket.prototype.canAdd = function (item) { + return (this.currentMassKg() + item.massKg) <= this.totalCapacityKg; + }; + Rocket.prototype.addCargo = function (cargo) { + if (this.canAdd(cargo)) { + this.cargoItems.push(cargo); + return true; + } + else { + return false; + } + }; + Rocket.prototype.addAstronaut = function (astronaut) { + if (this.canAdd(astronaut)) { + this.astronauts.push(astronaut); + return true; + } + else { + return false; + } + }; + return Rocket; +}()); +exports.Rocket = Rocket; diff --git a/studio/Rocket.ts b/studio/Rocket.ts index 000179c4..1d9ae791 100644 --- a/studio/Rocket.ts +++ b/studio/Rocket.ts @@ -1,50 +1,50 @@ -import { Payload } from './Payload'; -import { Cargo } from './Cargo'; -import { Astronaut } from './Astronaut'; - -export class Rocket implements Payload { - name: string; - totalCapacityKg: number; - cargoItems: Cargo[] = []; - astronauts: Astronaut[] = []; - massKg: number; - - constructor (name: string, totalCapacityKg: number) { - this.name = name; - this.totalCapacityKg = totalCapacityKg; - } - - sumMass (items: Payload[]): number { - let sum: number = 0; - for (let i=0; i < items.length; i++) { - sum += items[i].massKg; - } - return sum; - } - - currentMassKg (): number { - return this.sumMass(this.astronauts) + this.sumMass(this.cargoItems); - } - - canAdd(item: Payload): boolean { - return (this.currentMassKg() + item.massKg) <= this.totalCapacityKg; - } - - addCargo(cargo: Cargo): boolean { - if (this.canAdd(cargo)) { - this.cargoItems.push(cargo); - return true; - } else { - return false; - } - } - - addAstronaut(astronaut: Astronaut): boolean { - if (this.canAdd(astronaut)) { - this.astronauts.push(astronaut); - return true; - } else { - return false; - } - } +import { Payload } from './Payload'; +import { Cargo } from './Cargo'; +import { Astronaut } from './Astronaut'; + +export class Rocket implements Payload { + name: string; + totalCapacityKg: number; + cargoItems: Cargo[] = []; + astronauts: Astronaut[] = []; + massKg: number; + + constructor (name: string, totalCapacityKg: number) { + this.name = name; + this.totalCapacityKg = totalCapacityKg; + } + + sumMass (items: Payload[]): number { + let sum: number = 0; + for (let i=0; i < items.length; i++) { + sum += items[i].massKg; + } + return sum; + } + + currentMassKg (): number { + return this.sumMass(this.astronauts) + this.sumMass(this.cargoItems); + } + + canAdd(item: Payload): boolean { + return (this.currentMassKg() + item.massKg) <= this.totalCapacityKg; + } + + addCargo(cargo: Cargo): boolean { + if (this.canAdd(cargo)) { + this.cargoItems.push(cargo); + return true; + } else { + return false; + } + } + + addAstronaut(astronaut: Astronaut): boolean { + if (this.canAdd(astronaut)) { + this.astronauts.push(astronaut); + return true; + } else { + return false; + } + } } \ No newline at end of file diff --git a/studio/index.js b/studio/index.js index 591fd539..c6982c87 100644 --- a/studio/index.js +++ b/studio/index.js @@ -1,43 +1,43 @@ -"use strict"; -// Instructions are published in the online book. The URL is: -// https://education.launchcode.org/intro-to-professional-web-dev/chapters/typescript/studio.html -exports.__esModule = true; -var Astronaut_1 = require("./Astronaut"); -var Cargo_1 = require("./Cargo"); -var Rocket_1 = require("./Rocket"); -var falcon9 = new Rocket_1.Rocket('Falcon 9', 7500); -var astronauts = [ - new Astronaut_1.Astronaut(75, 'Mae'), - new Astronaut_1.Astronaut(81, 'Sally'), - new Astronaut_1.Astronaut(99, 'Charles') -]; -for (var i = 0; i < astronauts.length; i++) { - var astronaut = astronauts[i]; - var status_1 = ''; - if (falcon9.addAstronaut(astronaut)) { - status_1 = "On board"; - } - else { - status_1 = "Not on board"; - } - console.log(astronaut.name + ": " + status_1); -} -var cargo = [ - new Cargo_1.Cargo(3107.39, "Satellite"), - new Cargo_1.Cargo(1000.39, "Space Probe"), - new Cargo_1.Cargo(753, "Water"), - new Cargo_1.Cargo(541, "Food"), - new Cargo_1.Cargo(2107.39, "Tesla Roadster"), -]; -for (var i = 0; i < cargo.length; i++) { - var c = cargo[i]; - var loaded = ''; - if (falcon9.addCargo(c)) { - loaded = "Loaded"; - } - else { - loaded = "Not loaded"; - } - console.log(c.material + ": " + loaded); -} -console.log("Final cargo and astronaut mass: " + falcon9.currentMassKg() + " kg."); +"use strict"; +// Instructions are published in the online book. The URL is: +// https://education.launchcode.org/intro-to-professional-web-dev/chapters/typescript/studio.html +exports.__esModule = true; +var Astronaut_1 = require("./Astronaut"); +var Cargo_1 = require("./Cargo"); +var Rocket_1 = require("./Rocket"); +var falcon9 = new Rocket_1.Rocket('Falcon 9', 7500); +var astronauts = [ + new Astronaut_1.Astronaut(75, 'Mae'), + new Astronaut_1.Astronaut(81, 'Sally'), + new Astronaut_1.Astronaut(99, 'Charles') +]; +for (var i = 0; i < astronauts.length; i++) { + var astronaut = astronauts[i]; + var status_1 = ''; + if (falcon9.addAstronaut(astronaut)) { + status_1 = "On board"; + } + else { + status_1 = "Not on board"; + } + console.log(astronaut.name + ": " + status_1); +} +var cargo = [ + new Cargo_1.Cargo(3107.39, "Satellite"), + new Cargo_1.Cargo(1000.39, "Space Probe"), + new Cargo_1.Cargo(753, "Water"), + new Cargo_1.Cargo(541, "Food"), + new Cargo_1.Cargo(2107.39, "Tesla Roadster"), +]; +for (var i = 0; i < cargo.length; i++) { + var c = cargo[i]; + var loaded = ''; + if (falcon9.addCargo(c)) { + loaded = "Loaded"; + } + else { + loaded = "Not loaded"; + } + console.log(c.material + ": " + loaded); +} +console.log("Final cargo and astronaut mass: " + falcon9.currentMassKg() + " kg."); diff --git a/studio/index.ts b/studio/index.ts index c7e3bff3..89f60f92 100644 --- a/studio/index.ts +++ b/studio/index.ts @@ -1,47 +1,47 @@ -// Instructions are published in the online book. The URL is: -// https://education.launchcode.org/intro-to-professional-web-dev/chapters/typescript/studio.html - -import { Astronaut } from './Astronaut'; -import { Cargo } from './Cargo'; -import { Rocket } from './Rocket'; - -let falcon9: Rocket = new Rocket('Falcon 9', 7500); - -let astronauts: Astronaut[] = [ - new Astronaut(75, 'Mae'), - new Astronaut(81, 'Sally'), - new Astronaut(99, 'Charles') -]; - -for (let i = 0; i < astronauts.length; i++) { - let astronaut = astronauts[i]; - let status = ''; - if (falcon9.addAstronaut(astronaut)) { - status = "On board"; - } else { - status = "Not on board"; - } - console.log(`${astronaut.name}: ${status}`); -} - -let cargo: Cargo[] = [ - new Cargo(3107.39, "Satellite"), - new Cargo(1000.39, "Space Probe"), - new Cargo(753, "Water"), - new Cargo(541, "Food"), - new Cargo(2107.39, "Tesla Roadster"), -]; - -for (let i = 0; i < cargo.length; i++) { - let c = cargo[i]; - let loaded = ''; - if (falcon9.addCargo(c)) { - loaded = "Loaded" - } else { - loaded = "Not loaded" - } - console.log(`${c.material}: ${loaded}`); -} - -console.log(`Final cargo and astronaut mass: ${falcon9.currentMassKg()} kg.`); - +// Instructions are published in the online book. The URL is: +// https://education.launchcode.org/intro-to-professional-web-dev/chapters/typescript/studio.html + +import { Astronaut } from './Astronaut'; +import { Cargo } from './Cargo'; +import { Rocket } from './Rocket'; + +let falcon9: Rocket = new Rocket('Falcon 9', 7500); + +let astronauts: Astronaut[] = [ + new Astronaut(75, 'Mae'), + new Astronaut(81, 'Sally'), + new Astronaut(99, 'Charles') +]; + +for (let i = 0; i < astronauts.length; i++) { + let astronaut = astronauts[i]; + let status = ''; + if (falcon9.addAstronaut(astronaut)) { + status = "On board"; + } else { + status = "Not on board"; + } + console.log(`${astronaut.name}: ${status}`); +} + +let cargo: Cargo[] = [ + new Cargo(3107.39, "Satellite"), + new Cargo(1000.39, "Space Probe"), + new Cargo(753, "Water"), + new Cargo(541, "Food"), + new Cargo(2107.39, "Tesla Roadster"), +]; + +for (let i = 0; i < cargo.length; i++) { + let c = cargo[i]; + let loaded = ''; + if (falcon9.addCargo(c)) { + loaded = "Loaded" + } else { + loaded = "Not loaded" + } + console.log(`${c.material}: ${loaded}`); +} + +console.log(`Final cargo and astronaut mass: ${falcon9.currentMassKg()} kg.`); +