<body>
<pre>
<form>
<strong> Height:</strong> <input id ="Height"><br/>
<strong> Base: </strong> <input id ="Base"><br/>
<strong> Hypotenus: </strong> <input id ="Hypotenus"><br/>
</form>
<button type ="Button" onclick="Evaluate()">Find Area</button>
<p id ="Answer"> Answer will appear here </p>
<script>
function Evaluate() {
var H = document.getElementById("Height").value;
var B = document.getElementById("Base").value;
var Hy = document.getElementById("Hypotenus").value;
if (B == NaN || null) {
var Area = Math.sqrt(Math.pow(Hy, 2) - Math.pow(H, 2));
}
document.getElementById("Answer").innerHTML = Area;
}
</script>
</body>
I'm new to JavaScript and I've been trying to make a code that finds the formula of a triangle. My problem is after the if statement I would like to change the value of "Area" but I keep getting undefined
everytime I run the code. How do I change the value of a variable within an if statement?
Aucun commentaire:
Enregistrer un commentaire