Skip to content

Commit 94c9277

Browse files
committed
finished project; strange error on Part 4 LaunchCodeEducation#6
1 parent a42981c commit 94c9277

File tree

4 files changed

+124
-9
lines changed

4 files changed

+124
-9
lines changed

exercises/SpaceLocation.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
"use strict";
2+
exports.__esModule = true;
3+
exports.SpaceLocation = void 0;
4+
// Paste in the provided code here:
5+
var SpaceLocation = /** @class */ (function () {
6+
function SpaceLocation(name, kilometersAway) {
7+
this.name = name;
8+
this.kilometersAway = kilometersAway;
9+
}
10+
SpaceLocation.prototype.printDaysToLocation = function (location) {
11+
console.log(this.name + " would take " + this.getDaysToLocation(location.kilometersAway) + " days to get to " + location.name + ".");
12+
};
13+
return SpaceLocation;
14+
}());
15+
exports.SpaceLocation = SpaceLocation;

exercises/SpaceLocation.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,11 @@
11
// Paste in the provided code here:
2+
export class SpaceLocation {
3+
kilometersAway: number;
4+
name: string;
5+
6+
constructor(name: string, kilometersAway: number) {
7+
this.name = name;
8+
this.kilometersAway = kilometersAway;
9+
}
10+
11+
}

exercises/parts1-5.js

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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:

exercises/parts1-5.ts

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,74 @@
11
// URL for the instructions:
22
// https://education.launchcode.org/intro-to-professional-web-dev/chapters/typescript/exercises.html
3-
3+
import { SpaceLocation } from './SpaceLocation';
44

55
// Part 1: Declare (5) Variables With Type
6-
6+
// let spacecraftName: string = 'Determination';
7+
// let speedMph: number = 17500;
8+
let kilometersToMars: number = 225000000;
9+
let kilometersToTheMoon: number = 384400;
10+
// let milesPerKilometer: number = 0.621;
711

812

913
// Part 2: Print Days to Mars
10-
14+
// let milesToMars:number = kilometersToMars * milesPerKilometer;
15+
// let hoursToMars:number = milesToMars / speedMph;
16+
// let daysToMars: number = hoursToMars / 24;
1117

1218

1319
// Code an output statement here (use a template literal):
14-
20+
// console.log(`${spacecraftName} will take ${daysToMars} days to reach Mars. Red rocks!`)
1521

1622

1723
// Part 3: Create a Function ("getDaysToLocation")
1824

25+
// function getDaysToLocation(kilometersAway: number): number {
26+
// let milesAway:number = kilometersAway * milesPerKilometer;
27+
// let hoursToLocation:number = milesAway/speedMph;
28+
// let daysToLocation:number = hoursToLocation/24;
29+
// return daysToLocation;
30+
// }
1931

2032

2133
// Move your output statement from part 2 here. Update the template literal to call
2234
// the function and print the outputs for a Mars trip and a moon trip.
35+
// console.log(`${spacecraftName} will take ${getDaysToLocation(kilometersToMars)} days to reach Mars. M-A-R-S! MARS!`)
2336

24-
25-
37+
// console.log(`${spacecraftName} will take ${getDaysToLocation(kilometersToTheMoon)} days to reach the Moon. Grey rocks!`)
2638

2739
// Part 4: Create a Spacecraft Class
28-
40+
class Spacecraft {
41+
milesPerKilometer: number = 0.621;
42+
name: string;
43+
speedMph: number;
44+
constructor(name: string, speedMph: number) {
45+
this.name = name;
46+
this.speedMph = speedMph;
47+
}
48+
getDaysToLocation(kilometersAway: number): number {
49+
let milesAway:number = kilometersAway * this.milesPerKilometer;
50+
let hoursToLocation:number = milesAway/this.speedMph;
51+
let daysToLocation:number = hoursToLocation/24;
52+
return daysToLocation;
53+
}
54+
printDaysToLocation(location: SpaceLocation) {
55+
console.log(`${this.name} would take ${this.getDaysToLocation(location.kilometersAway)} days to get to ${location.name}.`);
56+
}
57+
}
2958

3059

3160

3261
// Create an instance of the class here:
33-
62+
let spaceShuttle = new Spacecraft('Determination', 17500);
3463

3564

3665
// Move your output statements from part 3 here. Update the template literals use the
3766
// instance of the class.
67+
// console.log(`${spaceShuttle.name} will take ${spaceShuttle.getDaysToLocation(kilometersToMars)} days to reach Mars. MARS!`)
68+
// console.log(`${spaceShuttle.name} will take ${spaceShuttle.getDaysToLocation(kilometersToTheMoon)} days to reach the Moon. Swiss cheese!`)
3869

39-
70+
spaceShuttle.printDaysToLocation(new SpaceLocation('Mars', kilometersToMars));
71+
spaceShuttle.printDaysToLocation(new SpaceLocation('the Moon', kilometersToTheMoon));
4072

4173
// Part 5: Export and Import the SpaceLocation Class
4274
// Add the required import statement BEFORE the part 1 concent.

0 commit comments

Comments
 (0)