繁体   English   中英

JavaScript 代码不工作并且没有出现调试错误

[英]JavaScript code doesn't work and doesn't come with a debug error

应该告诉你你的速度是否高到足以逃离目前只是不起作用的大气不知道为什么? 有帮助吗?

 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 Pl.net 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>

预期: output 要么是你的速度足够高要么太低

我注意到您的代码中存在一些错误:

#1 :您两次声明escapeVelocity ,但事实并非如此。

#2 :变量mrv未分配任何值。

#3 : 你的 function 没有关闭

#4: <center> :居中文本元素已弃用:不再推荐此功能。 虽然某些浏览器可能仍然支持它,但它可能已经从相关的 web 标准中删除,可能正在被删除,或者可能只是出于兼容性目的而保留。 避免使用它,并尽可能更新现有代码。 请注意,此功能可能随时停止工作。

 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 Pl.net 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>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM