Space Travel

Task

1. Create a program that displays how long it will take the Shuttle to get to Mars.

2. Create a program that displays how long it will take the Shuttle to get to the Moon.

TIP:
Declare and assign a variable for each item in the list
Use the Console to check the output of each type of variable

Information
Name of the space shuttle: Determination

Shuttle Speed (mph): 17,500

Distance to Mars (km): 225,000,000

Distance to the Moon (km): 384,400

Miles per kilometer: 0.621

Solution
Determine how many days it will take to reach Mars

mars will take

Determine how many days it will take to reach the Moon

moon will take

Instructions


Space Travel


Show Code

Code

window.onload = function() {
// declare variables
let spaceShuttle = “Determination”;
let shuttleSpeed = 17500;
console.log ( “Typeof ‘shuttle speed’ = ” + typeof shuttleSpeed );
let distanceMars = 225000000;
let distanceMoon = 384400;
const milesPerKilometer = 0.621;
let timeTaken = ” will take “;
console.log ( “Typeof ‘time taken’ = ” + typeof timeTaken );

//calculations

//miles to Mars – To get the miles to Mars by multiplying the distance to Mars in kilometers by the miles per kilometer.
let milesToMars = ( distanceMars * milesPerKilometer);
console.log ( “Typeof ‘miles to Mars’ = ” + typeof milesToMars );
//hours to Mars – To get the hours, you need to divide the miles to Mars by the shuttle’s speed.
let hoursToMars = ( milesToMars / shuttleSpeed);
console.log ( “Typeof ‘hours to Mars’ = ” + typeof hoursToMars );
//days to Mars – To get the days it will take to reach Mars, you need to divide the hours it will take to reach Mars by 24.
let daysToMars = ( hoursToMars / 24);
console.log ( “Typeof ‘days to Mars’ = ” + typeof daysToMars );

//miles to the Moon – To get the miles to the Moon by multiplying the distance to the Moon in kilometers by the miles per kilometer.
let milesToMoon = ( distanceMoon * milesPerKilometer);
console.log ( “Typeof ‘miles to the Moon’ = ” + typeof milesToMoon );
//hours to the Moon – To get the hours, you need to divide the miles to the Moon by the shuttle’s speed.
let hoursToMoon = ( milesToMoon / shuttleSpeed);
console.log ( “Typeof ‘hours to the Moon’ = ” + typeof hoursToMoon );
//days to the Moon – To get the days it will take to reach the Moon, you need to divide the hours it will take to reach the Moon by 24.
let daysToMoon = ( hoursToMoon / 24);
console.log ( “Typeof ‘days to the Moon’ = ” + typeof daysToMoon );

//display output
document.getElementById(“calculation-mars”).innerHTML = spaceShuttle + timeTaken + daysToMars + ” days to reach Mars.”;
document.getElementById(“calculation-moon”).innerHTML = spaceShuttle + timeTaken + daysToMoon + ” days to reach the Moon.”;
}