Skip to content

Commit a5467a4

Browse files
committed
Continued updates to move exercise instructions to a single file.
1 parent dde41b8 commit a5467a4

File tree

6 files changed

+94
-20
lines changed

6 files changed

+94
-20
lines changed

exercises/SpaceLocation.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
"use strict";
2+
exports.__esModule = true;
3+
// Paste in the provided code here:
4+
var SpaceLocation = /** @class */ (function () {
5+
function SpaceLocation(name, kilometersAway) {
6+
this.name = name;
7+
this.kilometersAway = kilometersAway;
8+
}
9+
return SpaceLocation;
10+
}());
11+
exports.SpaceLocation = SpaceLocation;

exercises/SpaceLocation.ts

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

exercises/part1-2.js

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,40 @@
1+
"use strict";
12
// URL for the instructions:
23
// https://education.launchcode.org/intro-to-professional-web-dev/chapters/typescript/exercises.html
4+
exports.__esModule = true;
5+
// Part 5: Add import statement here:
6+
var SpaceLocation_1 = require("./SpaceLocation");
37
// Part 1: Add the 5 variables here
4-
var spacecraftName = "Determination";
5-
var speedMph = 17500;
68
var kilometersToMars = 225000000;
79
var kilometersToTheMoon = 384400;
8-
var milesPerKilometer = 0.621;
910
// Code part 2 here:
10-
var milesToMars = kilometersToMars * milesPerKilometer;
11-
var hoursToMars = milesToMars / speedMph;
12-
var daysToMars = hoursToMars / 24;
1311
// Code the output statement here (use a template literal):
14-
console.log(spacecraftName + " would take " + daysToMars + " days to get to Mars.");
1512
// Part 3:
1613
// Code the "getDaysToLocation" function here:
1714
// Call the function and print the outputs for the Mars trip and the moon trip:
15+
// Part 4:
16+
/* Move the variables spacecraftName, speedMph, and milesPerKilometer into the
17+
Spacecraft class. Also move your getDaysToLocation function into the Spacecraft
18+
class. */
19+
// Define your Spacecraft class here:
20+
var Spacecraft = /** @class */ (function () {
21+
function Spacecraft(name, speedMph) {
22+
this.milesPerKilometer = 0.621;
23+
this.name = name;
24+
this.speedMph = speedMph;
25+
}
26+
Spacecraft.prototype.getDaysToLocation = function (kilometersAway) {
27+
var milesAway = kilometersAway * this.milesPerKilometer;
28+
var hoursToLocation = milesAway / this.speedMph;
29+
return hoursToLocation / 24;
30+
};
31+
Spacecraft.prototype.printDaysToLocation = function (location) {
32+
console.log(this.name + " would take " + this.getDaysToLocation(location.kilometersAway) + " days to get to " + location.name + ".");
33+
};
34+
return Spacecraft;
35+
}());
36+
// Create an instance of the class here:
37+
var spaceShuttle = new Spacecraft('Determination', 17500);
38+
// Print two outputs - one for the trip to Mars and one for the trip to the moon.
39+
spaceShuttle.printDaysToLocation(new SpaceLocation_1.SpaceLocation('Mars', kilometersToMars));
40+
spaceShuttle.printDaysToLocation(new SpaceLocation_1.SpaceLocation('the Moon', kilometersToTheMoon));

exercises/part1-2.ts

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,61 @@
11
// URL for the instructions:
22
// https://education.launchcode.org/intro-to-professional-web-dev/chapters/typescript/exercises.html
33

4+
// Part 5: Add import statement here:
5+
import { SpaceLocation } from './SpaceLocation';
6+
47
// Part 1: Add the 5 variables here
58

6-
let spacecraftName: string = "Determination";
7-
let speedMph: number = 17500;
89
let kilometersToMars: number = 225000000;
910
let kilometersToTheMoon: number = 384400;
10-
let milesPerKilometer: number = 0.621;
11-
1211

1312
// Code part 2 here:
14-
let milesToMars: number = kilometersToMars * milesPerKilometer;
15-
let hoursToMars: number = milesToMars/speedMph;
16-
let daysToMars: number = hoursToMars/24;
13+
1714

1815
// Code the output statement here (use a template literal):
19-
console.log(`${spacecraftName} would take ${daysToMars} days to get to Mars.`);
16+
2017

2118

2219
// Part 3:
2320
// Code the "getDaysToLocation" function here:
2421

2522

23+
// Call the function and print the outputs for the Mars trip and the moon trip:
2624

2725

26+
// Part 4:
27+
/* Move the variables spacecraftName, speedMph, and milesPerKilometer into the
28+
Spacecraft class. Also move your getDaysToLocation function into the Spacecraft
29+
class. */
30+
31+
// Define your Spacecraft class here:
32+
class Spacecraft {
33+
name: string;
34+
speedMph: number;
35+
milesPerKilometer: number = 0.621;
36+
37+
constructor(name: string, speedMph: number) {
38+
this.name = name;
39+
this.speedMph = speedMph;
40+
}
41+
42+
getDaysToLocation(kilometersAway: number): number {
43+
let milesAway: number = kilometersAway * this.milesPerKilometer;
44+
let hoursToLocation: number = milesAway/this.speedMph;
45+
46+
return hoursToLocation/24;
47+
}
48+
49+
printDaysToLocation(location: SpaceLocation) {
50+
console.log(`${this.name} would take ${this.getDaysToLocation(location.kilometersAway)} days to get to ${location.name}.`);
51+
}
52+
53+
}
54+
55+
// Create an instance of the class here:
56+
let spaceShuttle = new Spacecraft('Determination', 17500)
2857

29-
// Call the function and print the outputs for the Mars trip and the moon trip:
3058

59+
// Print two outputs - one for the trip to Mars and one for the trip to the moon.
60+
spaceShuttle.printDaysToLocation(new SpaceLocation('Mars', kilometersToMars));
61+
spaceShuttle.printDaysToLocation(new SpaceLocation('the Moon', kilometersToTheMoon));

exercises/part4.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
let kilometersToMars: number = 225000000;
2-
let kilometersToTheMoon: number = 384400;
1+
// let kilometersToMars: number = 225000000;
2+
// let kilometersToTheMoon: number = 384400;
33

44

55
// The variables that are commented out will be moved into the Spacecraft class

exercises/part5.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// Add your import statement here:
22

33

4-
let kilometersToMars: number = 225000000;
5-
let kilometersToTheMoon: number = 384400;
4+
// let kilometersToMars: number = 225000000;
5+
// let kilometersToTheMoon: number = 384400;
66

77
class Spacecraft {
88
milesPerKilometer: number = 0.621;

0 commit comments

Comments
 (0)