I'm making a website with a sort of javascript application. I worked on it very long, but in the end it all worked. So as I was cleaning up all my code of comments, I refreshed my site and tested this application one more time, but it didn't work anymore. The error that I get says:
Uncaught SyntaxError: Unexpected token }
Down here at line 13 is where the error occurs.
<table class="calculator" id="calculator">
<tr>
<th>Materiaal</th>
<th>Waarde(€/kg)</th>
<th>Hoeveelheid(kg)</th>
<th>Subtotaal</th>
</tr>
<tr>
<td>IJzer</td>
<td>0,15</td>
<td>
<input type="number" min="0" id="ironinput" onchange=calculator( "iron") onkeyup=calculator( "iron") value=0>
</td> <!--This is where the error occurs-->
<td id="ironoutput">0.00</td>
</tr>
This is my javascript:
var materials = ["iron", "copper", "aluminum"];
var iron = 0.15;
var copper = 4.00;
var aluminum = 0.70;
function calculator(material) {
var input = document.getElementById(material + "input").value;
switch (material) {
case "iron":
document.getElementById(material + "output").innerHTML = (input * iron).toFixed(2);
break;
case "copper":
document.getElementById(material + "output").innerHTML = (input * copper).toFixed(2);
break;
case "aluminum":
document.getElementById(material + "output").innerHTML = (input * aluminum).toFixed(2);
break;
}
document.getElementById("total").innerHTML = getTotal().toFixed(2);
};
function getTotal() {
var total = 0;
for (var i = 0; i < materials.length; i++ ) {
total += Number(document.getElementById(materials[i] + "output").innerHTML);
}
return total;
};
I hope someone can help me, I'm a beginner at web development so I hope I can get a relativily easy solution and a explanation why this happens. Thank you guys.
Aucun commentaire:
Enregistrer un commentaire