<!doctype html>
<html lang='nl'>
<head>
<meta charset='utf-8' />
<title>Waterprogramma</title>
</head>
<body>
Water prijs / euro: <input id='waterprijs' />
Water hoeveelheid / liter: <input id='hoeveelheid' />
Max bedrag / euro: <input id='maxbedrag' />
Liter gratis / persoon: <input id='gratis' />
<button onclick='calculate();'>ga!</button>
<pre id='output'></pre>
<script>
function output(what)
{
document.getElementById('output').innerHTML += what + '\n';
}
function calculate()
{
var waterprijs = document.getElementById('waterprijs').value,
hoeveelheid = document.getElementById('hoeveelheid').value,
maxbedrag = document.getElementById('maxbedrag').value,
gratis = document.getElementById('gratis').value;
var totaal = waterprijs * hoeveelheid;
var totaalMetGratis = waterprijs * (hoeveelheid - gratis);
document.getElementById('output').innerHTML = ''; // wis vorige input
output('Prijs WATER| ' + waterprijs + ' €');
output('Hoeveelheid LITER| ' + hoeveelheid + ' €');
output('Streefbedrag EURO| ' + maxbedrag + ' € ');
output(gratis + ' Liter gratis per persoon');
output('Totaal liter| ' + hoeveelheid + ' Zonder gratis liter| ' + gratis);
output('Totaal EURO| ' + totaal + ' Zonder gratis liter| ' + gratis);
output('Totaal EURO| ' + totaalMetGratis + ' Met gratis liter');
output('<br />');
if(maxbedrag > totaalMetGratis)
{
// ?
output('U zit onder uw streefbedrag');
}else{
output('U zit boven uw streefbedrag');
}
}
</script>
</body>
</html>