我正在尝试使用HTML和Javascript编写一个Pythagorean定理计算器,以便它可以找到给定两个边值的任何边,所以我使用了if语句,但我似乎无法理解为什么它不能工作
下面是HTML和JavaScript代码
function do_things() {
var a = parseFloat(document.getElementById("a").value);
var b = parseFloat(document.getElementById("b").value);
var c = parseFloat(document.getElementById("c").value);
var output = document.getElementById("output");
if (a=0, b>0){
var c = Math.sqrt(c*c - b*b)
var node = document.createElement("LI"); // Create a <li> node
var textnode = document.createTextNode(c); // Create a text node
node.appendChild(textnode); // Append the text to <li>
document.getElementById("output").appendChild(node);
} else if (c=0, b>0){
var c = Math.sqrt(a*a + b*b)
console.log(0)
var node = document.createElement("LI"); // Create a <li> node
var textnode = document.createTextNode(c); // Create a text node
node.appendChild(textnode); // Append the text to <li>
document.getElementById("output").appendChild(node);
}
}
<h1>Calc</h1>
<p1>Calculate the Hypotnuse given the A and B value</p1>
<p>Side A: <input type="text" id="a"/></p>
<br>
<p>Side B: <input type="text" id="b"/></p>
<br>
<p>Hypotnuse: <input type="text" id="c"/></p>
<br>
<button type="button" onclick="do_things()">Find the missing value</button>
<br>
<p id="output">The Missing hypotnuse</p>
发布于 2018-06-11 03:56:33
'===‘在这里可能返回false,因为您正在将值解析为float,这将得到0.00。
https://stackoverflow.com/questions/50787355
复制相似问题