I am trying to make a site which will display various sentences depending on the variable "d". The plan is if "d" is exactly 0, the first line will be displayed, as well as the value of d will be displayed in the paragraph with a class of "text".
<!doctype HTML>
<html>
<head>
<link href="main.css" rel="stylesheet" />
<meta charset="utf-8">
<link href="http://ift.tt/1qQRi4V" rel="stylesheet">
</head>
<body class="Ubuntu">
<nav>
<div>
<h1>Beregn antal diskriminanter</h1>
</div>
</nav>
<div align="center" class="main_container">
<table>
<form method="POST" name="diskriminant" action="diskriminant.html">
<tr>
<td>
<p> Indtast a </p>
</td>
<td>
<input type="number" name="numA" size="6" class="input-form"/></p>
</td>
</tr>
<tr>
<td>
<p> Indtast b </p>
</td>
<td>
<input type="number" name="numB" size="6" class="input-form"/></p>
</td>
</tr>
<tr>
<td>
<p> Indtast c </p>
</td>
<td>
<input type="number" name="numC" size="6" class="input-form"/></p>
</td>
</tr>
<tr>
<td colspan="2" align="center">
<p><input type="button" name="knap" value="Beregn" onkeydown="enter()" onclick="beregner()"class="button Ubuntu"/></p>
</td>
</tr>
<tr>
<td colspan="2" align="center">
<p id="text" class="align"></p> <br> <p id="result" class="align"></p>
</td>
</tr>
</form>
</table>
</div>
<footer>
</footer>
<script>
function beregner() {
var a;
var b;
var c;
var d;
var res;
a=document.diskriminant.numA.value;
b=document.diskriminant.numB.value;
c=document.diskriminant.numC.value;
d=Math.pow(( +b),2)-4*a*c;
if (d = 0) {
res = "Der er ingen nulpunkter";
}
else if (d < 0) {
res ="Der er et nulpunkt";
}
else {
res ="Der er to nulpunkter";
}
document.getElementById('text').innerHTML=+d;
document.getElementById('result').innerHTML=res;
}
</script>
</body>
</html>
Aucun commentaire:
Enregistrer un commentaire