$(function () { //jQuery trick to run only after page has been rendered
h = 1000; // initial altitude [meters]
v = 0; // initial descent speed [m/s]
g = 1.622; // lunar gravity acceleration [m/s^2]
m = 7000; // LEM empty mass
c = 8000; // LEM initial ergol mass
p = 45000; // LEM engine power at 100% [Newton]
t = 10; // sampling period [seconds]
div = document.getElementById('myDiv');
do {
var l = document.createElement('p');
s = "alt=" + h.toFixed(2) + " vel=" + v.toFixed(2) + " fuel=" + c.toFixed(0);
l.textContent = s
div.appendChild(l);
e = 0;
if (c > 0) {
var e = prompt(s + " power %", "0");
try {
e = parseInt(e);
} catch (Error) {
e = 0;
}
}
l.textContent = "alt=" + h.toFixed(2) + " vel=" + v.toFixed(2) + " fuel=" + c.toFixed(0) + " pow=" + e.toFixed(0) + "%";
c = c - t * e; // fuel decrease
var a = g - 0.01 * p * e / (m + c); // downwards acceleration
v = v + a * t; // speed integration
h = h - v * t; // position integration
}
while (h > 0);
var l = document.createElement('p');
if (v < 1) l.textContent = "Houston : The Eagle has landed."
else if (v < 10) l.textContent = "Houston : The Eagle has crashed vel=" + v.toFixed(2)
else l.textContent = "The Moon has a new crater " + h.toFixed(0) + " m deep"
div.appendChild(l);
});
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.