0

should tell you if your velocity is high enough to escape the atmosphere currently just not working don't know why? any help?

var m, r, v, escapeVelocity;
var outputText, missionMessage;

function validate() {
  var escapeVelocity = Math.sqrt((2 * 6.67 * (Math.pow(10, -11)) * m) / r);
  console.log(escapeVelocity)
  if (v > escapeVelocity) {
    outputText = "This speed is fast enough to escape the atmosphere!";
  } else {
    v <= escapeVelocity
    outputText = "you will NOT escape the atmosphere at this speed";
  }
  document.getElementById("output_Text").innerHTML = outputText;
}
<center>Please enter the Planet Mass(m), Radius(R) and the Velocity(v).<br>Good Luck!!!!</br>
</center>
M: <input id="m" /><br />
<br/> R: <input id="r" /><br />
<br/> V: <input id="v" /><br />
<br/>
<button onclick="validate()">Calculate</button>
<p id="output_Text"></p>

expected: an output of either yes your velocity is high enough or if it's too low

ThS
  • 4,597
  • 2
  • 15
  • 27
  • You aren't setting `v,m,r` to anything in your example. – Ryan Wilson Dec 01 '22 at 17:18
  • You need to link the variables to the inputs. See https://stackoverflow.com/q/11563638 – d4nyll Dec 01 '22 at 17:19
  • Also you randomly have, "v <= escapeVelocity" in the else statement. – Aadmaa Dec 01 '22 at 17:19
  • I wanted to create a snippet from your code, but you html is invalid – Konrad Dec 01 '22 at 17:22
  • v m and r are inputted by the user and ive changed the else to an else if i think it might be the maths line with the escape velocity but i dont really know how to do the maths within java script – Harrison Buck Dec 01 '22 at 17:38
  • Also, you are declaring **escapeVelocity** twice which shouldn't be the case and variables **m**, **r**, and **v** are not assigned to any value. – Namwanza Ronald Dec 01 '22 at 17:40
  • honestly if someone can just make new code that does the same thing and works i will send you a tenner but has to be in javaScript – Harrison Buck Dec 01 '22 at 17:46
  • Please stop offering money in exchange for answers. I edited your question to remove that part. It is contrary to the Terms of Service and will likely get you kicked off the network. – Heretic Monkey Dec 01 '22 at 18:21
  • I think it's one thing to use SO to answer a legitimate issue that someone is having as part of their professional, school, or personal work. But actually fixing someone else's (apparent) homework doesn't seem like what SO is for. – tobylaroni Dec 01 '22 at 18:31

1 Answers1

1

I noticed a few mistakes in your code:

#1: you are declaring escapeVelocity twice which shouldn't be the case.

#2: variables m, r, and v are not assigned to any value.

#3: Your function is not closed

#4: <center>: The Centered Text element Deprecated: This feature is no longer recommended. Though some browsers might still support it, it may have already been removed from the relevant web standards, may be in the process of being dropped, or may only be kept for compatibility purposes. Avoid using it, and update existing code if possible. Be aware that this feature may cease to work at any time.

function validate() {
  var m = document.getElementById("v").value;
  var r = document.getElementById("r").value;
  var v = document.getElementById("v").value;
  var outputText, missionMessage;
  var escapeVelocity = Math.sqrt((2 * 6.67 * (Math.pow(10, -11)) * m) / r);
  console.log(escapeVelocity)
  if (v > escapeVelocity) {

    outputText = "This speed is fast enough to escape the atmosphere!";
  } else {
    outputText = "you will NOT escape the atmosphere at this speed";
  }
  document.getElementById("output_Text").innerHTML = outputText;
}
<div style="text-align:center">
  Please enter the Planet Mass(m), Radius(R) and the Velocity(v).<br /> Good Luck!!!!
</div>
M: <input id="m" /><br />
<br/> R: <input id="r" /><br />
<br/> V: <input id="v" /><br />
<br/>
<button onclick="validate()">Calculate</button>
<p id="output_Text"></p>
ThS
  • 4,597
  • 2
  • 15
  • 27
Namwanza Ronald
  • 150
  • 1
  • 1
  • 12
  • The `br` element is empty, and should be written as `
    ` in HTML. Ditto with `input`. Also, `center` has be deprecated since HTML4, and cannot be placed in the `head` element.
    – Heretic Monkey Dec 01 '22 at 18:19
  • Well, I only focused on fixing the javascript code and didn't pay attention to the html, but will go a head and improve my answer above. Thanks – Namwanza Ronald Dec 01 '22 at 18:22
  • 1
    @NamwanzaRonald - I think Monkey was just pointing out what remains to be fixed. You addressed the major problems and that's fine. +1 – Yogi Dec 01 '22 at 18:33