首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >用HTML和JavaScript实现勾股定理计算器

用HTML和JavaScript实现勾股定理计算器
EN

Stack Overflow用户
提问于 2018-06-11 03:34:39
回答 1查看 2K关注 0票数 0

我正在尝试使用HTML和Javascript编写一个Pythagorean定理计算器,以便它可以找到给定两个边值的任何边,所以我使用了if语句,但我似乎无法理解为什么它不能工作

下面是HTML和JavaScript代码

代码语言: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);
  }
}
代码语言:javascript
复制
<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>

EN

回答 1

Stack Overflow用户

发布于 2018-06-11 03:56:33

'===‘在这里可能返回false,因为您正在将值解析为float,这将得到0.00。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50787355

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档