Write a script that will calculate a person’s weight on each planet of the solar
ID: 3598254 • Letter: W
Question
Write a script that will calculate a person’s weight on each planet of the solar system, the sun, and the moon. You should create an html form with text boxes for each planet (also the sun and moon). You should also have a text box for a person to enter their weight on Earth. When the user clicks on a button, a javascript function should be called that calculates each weight and puts the results in the corresponding text boxes in the form. Use the Math.round method to round the numbers to the nearest whole number. Here are some formulas for the conversions.
Mercury= weight * .378
Venus = weight * .907
Mars = weight * .377
Jupiter = weight * 2.364
Saturn = weight * .916
Uranus = weight * .889
Neptune = weight * 1.125
Pluto = weight * .067
Sun = weight * 27.072
Moon = weight * .166
Explanation / Answer
Hello ,Plz find your ans-
Just copy and paste this code in to notepad and save as html and open into any browser,U will get ur ans.
<!DOCTYPE html>
<html>
<body>
<form action="javascript:Weight(earth);">
Enter Your Weight on Earth:<br>
<input type="text" name="earth">
<br><br>
Mercury:<br>
<input type="text" name="mercury">
<br>
Venus:<br>
<input type="text" name="venus">
<br>
Mars:<br>
<input type="text" name="mars">
<br>
Jupiter:<br>
<input type="text" name="jupiter">
<br>
Saturn:<br>
<input type="text" name="saturn">
<br>
Uranus:<br>
<input type="text" name="uranus">
<br>
Neptune:<br>
<input type="text" name="neptune">
<br>
Pluto:<br>
<input type="text" name="pluto">
<br>
Sun:<br>
<input type="text" name="sun">
<br>
Moon:<br>
<input type="text" name="moon">
<br>
<input type="submit" value="Calculate" id="submit">
</form>
<script>
var planetsArray = [{name: "mercury",weight: 0.378}, {name: "venus",weight: 0.907}, {name: "mars",weight: 0.377}, {name: "jupiter",weight: 2.364}, {name: "saturn",weight: 0.916}, {name: "uranus",weight: 0.889}, {name: "neptune",weight: 1.125}, {name: "pluto",weight: 0.067}, {name: "sun",weight:27.072}, {name: "moon",weight: 0.166}],
submitButton = document.getElementById('submit');
// Attach click event
submitButton.onclick = function (e) {
e.preventDefault();
var earth = document.getElementsByName('earth')[0];
planetsArray.forEach(function (p) {
var elem = document.getElementsByName(p.name)[0],
weight = p.weight * +earth.value;
elem.value = weight.toFixed(2);
});
};
</script>
</body>
</html>
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.