I'm trying to create a calculator that takes a number as input, decides in which range this number is, and adds a corresponding price to the basic price (currently set to 0). However, I'm stuck at a rather simple for-loop I inserted to iterate over the ranges (in seizprijs). Without the for-loop, the code appears to do just fine. However, if I run the code including the for-loop, the function returns 'not defined'.
I'm completely new to coding, so I expect it to be a simple issue. However, I tried every suggestion I could find online, and nothing seems to work.
const seizprijs = [
{tijd : "winter", bdatum : 1, edatum : 5, prijs : 45},
{tijd: "lente", bdatum: 5, edatum: 9, prijs: 50}
];
function myFunction() {
var prijs = 0;
var vdat = document.getElementById("datum");
var vdatum = vdat.value;
for (var x = 0, x < seizprijs.length, x++){
if (vdatum > seizprijs[1].bdatum && vdatum < seizprijs[1].edatum)
{
prijs += seizprijs[1].prijs;
}
}
document.getElementById("demo").innerHTML = "Totaalprijs:" + prijs;
}
<h1>Boeking</h1>
<p id="demo">Totaalprijs: </p>
<form id="boeking">
<input type="number" name="datum" id="datum">
</form>
<button type="button" onclick="myFunction()">Prijs berekenen</button>