Skip to content

more stuff #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions exercises/parts1-5.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// URL for the instructions:
// https://education.launchcode.org/intro-to-professional-web-dev/chapters/typescript/exercises.html
// Part 1: Declare (5) Variables With Type
var spacecraftName = 'Determination';
var speedMph = 17500;
var kilometersToMars = 225000000;
var kilometersToTheMoon = 384400;
var milesPerKilometer = 0.621;
// Part 2: Print Days to Mars
var milesToMars = kilometersToMars * milesPerKilometer;
var hoursToMars = milesToMars / speedMph;
var daysToMars = hoursToMars / 24;
console.log(spacecraftName + " will take " + daysToMars + " days to get to Mars");
// Code an output statement here (use a template literal):
// Part 3: Create a Function ("getDaysToLocation")
function getDaysToLocation(kilometersAway) {
var milesAway = kilometersToMars * milesPerKilometer;
var hoursToLocation = milesToMars / speedMph;
return milesAway * hoursToLocation;
}
;
console.log(spacecraftName + " will take " + getDaysToLocation(kilometersToMars) + " days to get to Mars");
console.log(spacecraftName + " will take " + getDaysToLocation(kilometersToTheMoon) + " days to get to the Moon");
// Move your output statement from part 2 here. Update the template literal to call
// the function and print the outputs for a Mars trip and a moon trip.
// Part 4: Create a Spacecraft Class
// Create an instance of the class here:
// Move your output statements from part 3 here. Update the template literals use the
// instance of the class.
// Part 5: Export and Import the SpaceLocation Class
// Add the required import statement BEFORE the part 1 concent.
// Add the printDaysToLocation function to the Spacecraft class.
// Paste in the code from step 6 here:
30 changes: 25 additions & 5 deletions exercises/parts1-5.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,18 @@


// Part 1: Declare (5) Variables With Type

let spacecraftName: string= 'Determination';
let speedMph: number= 17500;
let kilometersToMars: number= 225000000;
let kilometersToTheMoon: number= 384400;
let milesPerKilometer: number= 0.621;


// Part 2: Print Days to Mars

let milesToMars: number= kilometersToMars * milesPerKilometer
let hoursToMars: number= milesToMars / speedMph
let daysToMars: number= hoursToMars / 24
console.log(`${spacecraftName} will take ${daysToMars} days to get to Mars`)


// Code an output statement here (use a template literal):
Expand All @@ -16,11 +23,24 @@

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



function getDaysToLocation(kilometersAway:number):number {
let milesAway = kilometersToMars * milesPerKilometer;
let hoursToLocation = milesToMars / speedMph;
return milesAway*hoursToLocation
};
// Move your output statement from part 2 here. Update the template literal to call
console.log(`${spacecraftName} will take ${getDaysToLocation(kilometersToMars)} days to get to Mars`)
console.log(`${spacecraftName} will take ${getDaysToLocation(kilometersToTheMoon)} days to get to the Moon`)
// the function and print the outputs for a Mars trip and a moon trip.

class Spacecraft{
milesPerKilometer: number = 0.621;
name: string;
speedMph: number;
constructor(name: string, speedMph:number){
this.name =
this.speedMph =
}
}



Expand Down