|
| 1 | +"use strict"; |
| 2 | +exports.__esModule = true; |
| 3 | +// URL for the instructions: |
| 4 | +// https://education.launchcode.org/intro-to-professional-web-dev/chapters/typescript/exercises.html |
| 5 | +var SpaceLocation_1 = require("./SpaceLocation"); |
| 6 | +// Part 1: Declare (5) Variables With Type |
| 7 | +// let spacecraftName: string = 'Determination'; |
| 8 | +// let speedMph: number = 17500; |
| 9 | +var kilometersToMars = 225000000; |
| 10 | +var kilometersToTheMoon = 384400; |
| 11 | +// let milesPerKilometer: number = 0.621; |
| 12 | +// Part 2: Print Days to Mars |
| 13 | +// let milesToMars:number = kilometersToMars * milesPerKilometer; |
| 14 | +// let hoursToMars:number = milesToMars / speedMph; |
| 15 | +// let daysToMars: number = hoursToMars / 24; |
| 16 | +// Code an output statement here (use a template literal): |
| 17 | +// console.log(`${spacecraftName} will take ${daysToMars} days to reach Mars. Red rocks!`) |
| 18 | +// Part 3: Create a Function ("getDaysToLocation") |
| 19 | +// function getDaysToLocation(kilometersAway: number): number { |
| 20 | +// let milesAway:number = kilometersAway * milesPerKilometer; |
| 21 | +// let hoursToLocation:number = milesAway/speedMph; |
| 22 | +// let daysToLocation:number = hoursToLocation/24; |
| 23 | +// return daysToLocation; |
| 24 | +// } |
| 25 | +// Move your output statement from part 2 here. Update the template literal to call |
| 26 | +// the function and print the outputs for a Mars trip and a moon trip. |
| 27 | +// console.log(`${spacecraftName} will take ${getDaysToLocation(kilometersToMars)} days to reach Mars. M-A-R-S! MARS!`) |
| 28 | +// console.log(`${spacecraftName} will take ${getDaysToLocation(kilometersToTheMoon)} days to reach the Moon. Grey rocks!`) |
| 29 | +// Part 4: Create a Spacecraft Class |
| 30 | +var Spacecraft = /** @class */ (function () { |
| 31 | + function Spacecraft(name, speedMph) { |
| 32 | + this.milesPerKilometer = 0.621; |
| 33 | + this.name = name; |
| 34 | + this.speedMph = speedMph; |
| 35 | + } |
| 36 | + Spacecraft.prototype.getDaysToLocation = function (kilometersAway) { |
| 37 | + var milesAway = kilometersAway * this.milesPerKilometer; |
| 38 | + var hoursToLocation = milesAway / this.speedMph; |
| 39 | + var daysToLocation = hoursToLocation / 24; |
| 40 | + return daysToLocation; |
| 41 | + }; |
| 42 | + Spacecraft.prototype.printDaysToLocation = function (location) { |
| 43 | + console.log(this.name + " would take " + this.getDaysToLocation(location.kilometersAway) + " days to get to " + location.name + "."); |
| 44 | + }; |
| 45 | + return Spacecraft; |
| 46 | +}()); |
| 47 | +// Create an instance of the class here: |
| 48 | +var spaceShuttle = new Spacecraft('Determination', 17500); |
| 49 | +// Move your output statements from part 3 here. Update the template literals use the |
| 50 | +// instance of the class. |
| 51 | +// console.log(`${spaceShuttle.name} will take ${spaceShuttle.getDaysToLocation(kilometersToMars)} days to reach Mars. MARS!`) |
| 52 | +// console.log(`${spaceShuttle.name} will take ${spaceShuttle.getDaysToLocation(kilometersToTheMoon)} days to reach the Moon. Swiss cheese!`) |
| 53 | +spaceShuttle.printDaysToLocation(new SpaceLocation_1.SpaceLocation('Mars', kilometersToMars)); |
| 54 | +spaceShuttle.printDaysToLocation(new SpaceLocation_1.SpaceLocation('the Moon', kilometersToTheMoon)); |
| 55 | +// Part 5: Export and Import the SpaceLocation Class |
| 56 | +// Add the required import statement BEFORE the part 1 concent. |
| 57 | +// Add the printDaysToLocation function to the Spacecraft class. |
| 58 | +// Paste in the code from step 6 here: |
0 commit comments