我们最近开始在我的 HTML 课程中使用 Javascript,我似乎在我的所有程序中都遇到了一个我无法完全挑出的问题。我会问老师,但我一直在家里工作,我们正在休息,这会一直在吃我。我已经查看了“功能未定义”问题的其他答案,但他们并没有为我做这件事。那么我一直做错了什么?我敢打赌我的格式有问题。
<!DOCTYPE html>
<html>
<head><title>Area and Perimeter of a trapezoid</title></head>
<center><body>
<h1>Area and Perimeter of a Trapezoid</h1>
<p>Enter the first base length:
<input id="b1" type="text"> </br>
Enter the second base length:
<input id="b2" type="text"> </br>
Enter the height of the trapezoid:
<input id="height" type="text"> </br>
Enter the length of the sides of the trapezoid:
<input id="side" type="text"> </br>
</p>
<button type="button" onclick="trapArea()">Area</button>
<p id="area"></p>
<button type="button" onclick="trapPer()">Perimeter</button>
<p id="perimeter"></p>
<script>
function trapArea()
{
var b1=document.getElementById("b1");
var b2=document.getElementById("b2");
var height=document.getElementById("height");
var area=(.5*(b1+b2)*height);
document.getElementById("area").innerHTML="The area of this trapezoid is "+area+".</br>".
}
function trapPer()
{
var b1=document.getElementById("b1");
var b2=document.getElementById("b2");
var side=document.getElementById("side");
var perimeter=(b1+b2+side);
document.getElementById("perimeter").innerHTML="The perimeter of this trapezoid is "+perimeter+".</br>".
}
</script>
</center>
</body>
</html>