javascript - 为什么我的 if 语句没有显示在我的网站上?
问题描述
我试图弄清楚为什么我的 if 语句没有显示在我的网站上。我的第一个脚本正在显示三角形区域,我想尝试找出如何使用 ifelse 语句显示哪个三角形更大。这是我第一次尝试使用这些并希望得到一些帮助。
编辑:我已经修复了我的 if 语句的括号,但现在即使它们不正确,它也会显示它们。我应该如何解决这个问题?
编辑2:谢谢大家的惊人帮助。我很感激,我的代码现在可以工作了!
<script>
var Base1 = parseFloat(prompt("Base1", "100"));
var Height1 = parseFloat(prompt("Height1", "100"));
var Base2 = parseFloat(prompt("Base2", "100"));
var Height2 = parseFloat(prompt("Height2", "100"));
document.write("<p>triangle1's Volume is : "+Base1 * Height1/2+"</p>");
document.write("<p>triangle2's Volume is : "+Base2 * Height2/2+"</p>");
</script>
<script>
if((Base1 * Height1/2) == (Base2 * Height2/2));
{
document.write("<p>the triangles are the same size</p>");
}
if ((Base1 * Height1/2) > (Base2 * Height2/2));
{
document.write("<p>triangle 1 is bigger</p>");
}
if ((Base1 * Height1/2) < (Base2 * Height2/2));
{
document.write("<p>triangle2 is bigger</p>");
}
</script>
解决方案
您的 if 条件语法不正确:
<script>
var Base1 = parseFloat(prompt("Base1", "100"));
var Height1 = parseFloat(prompt("Height1", "100"));
var Base2 = parseFloat(prompt("Base2", "100"));
var Height2 = parseFloat(prompt("Height2", "100"));
document.write("<p>triangle1's Volume is : "+Base1 * Height1/2+"</p>");
document.write("<p>triangle2's Volume is : "+Base2 * Height2/2+"</p>");
</script>
<script>
if((Base1 * Height1/2) === (Base2 * Height2/2))
{
document.write("<p>the triangles are the same size</p>");
} else if ((Base1 * Height1/2) > (Base2 * Height2/2))
{
document.write("<p>triangle 1 is bigger</p>");
}
else
{
document.write("<p>triangle2 is bigger</p>");
}
</script>
推荐阅读
- c# - 如何从另一个表单重新加载用户控件
- kubernetes - 如何检查 kubeapierrorhigh 以及如何修复?
- php - Woocommerce agroup 并仅对唯一文件名进行排序,不要重复它们
- python - Python struct 解压二进制 com 数据
- python-3.x - 如何使用 Flask 重定向将 HEAD 请求更改为 GET 请求?
- java - 为什么我的扫描仪在读取文件时会创建一个额外的输入?
- python-3.x - numpy polyfit 的问题
- sql - Oracle SQL regexp_substr 数提取行为
- javascript - 点击提交后关闭 Modal
- python - 使用 zipfile 时收到一个奇怪的错误,我不知道为什么。程序看起来不错