Answered You can hire a professional tutor to get the answer.
Try to contain as much of your code as possible inside of functions that are well named and can be reused.
The Interstellar Traveler
The goal of this assignment is to use functions. Try to contain as much of your code as possible inside of functions that are well named and can be reused. At a minimum your code must use four functions.
You are to a program that aids an astronaut traveling to the planets (and moons) of our solar system. The planetary bodies in question are
- MERCURY
- VENUS
- EARTH
- MOON
- MARS
- JUPITER
- SATURN
- URANUS
- NEPTUNE
- PLUTO
Requirements
Use the table above as the conversion ratios for the various planets. Build functions that perform the following tasks.
- Ask the user to enter a weight and return the number they entered.
- Ask the user to enter a planet and return the name of the planet they entered.
- Calculate the weight of the user on the other planet and return the new weight.
- Print an output message to the user in an alert.
Program expectations
- Your code must use a minimum of the four functions described above.
- The functions that produce new data must have return statements that correctly return values.
- The functions that gather input do not need parameters as they do not need to accept input.
- The conversion function should accept input parameters and return a value.
- The print function should also take input parameters.
- The final message should display the converted weight rounded to two decimal places.
- For extra credit you can enhance this program by allowing the user to tell you their weight and the planet they are currently on. Then ask them which planet they are visiting and output their weight on that planet. A hint to get you started is that it makes sense to convert everything to a known weight (that of Earth) and then convert to the weight on the other planet. I would probably make use two conversion functions. One function to convert from any planet weight to Earth weight and another to convert from Earth weight to any other planet weight.
Some general coding guidelines
- Add 'use strict' at the top of every js file.
- Parameter names in functions should have a space after each one.
- Don't put a space between the name of the function and the opening parenthesis.
- Do put a space between the closing parenthesis and the opening curly brace.
- The opening curly brace should be on the same line as the function declaration.
- The closing curly brace should be on a line all by itself.
- Code within a function should be indented.