I am trying to check if the answers from a user are correct. The answers of the user are stored in variable "stad". The correct options are stored in variable "collectie". However, this variable is an array with a nested array. So i first loop through the "collectie", check if the collectie element is not an array and if not, check that the submitted value is within this collectie element.
If the collectie element is an array, i have to alter a little bit the function so the variable checks whether the answer is within the nested array.
I have the following:
function nakijken() {
var collectie = ["parijs", "8", "ijsselmeer", ["Volkswagen", "Audi", "Opel", "Porsche", "BMW", "Mercedes", "Mercedes-Benz"],
["Texel", "Vlieland", "Terschelling", "Ameland", "Schiermonnikoog"]];
var stad = [];
var a = 0;
stad.push(document.getElementsByTagName("input"));
collectie.forEach(uitpakken);
function uitpakken(antwoord) {
if (!Array.isArray(antwoord)) {
stad.forEach(myfunction);
function myfunction(item) {
if (antwoord.includes(item.value.toLowerCase())) {
item.style.background = "green";
a++;
} else {
antwoord.style.background = "red";
}
}
}
else{
antwoord.Foreach(uitpakken);
function uitpakken(antwoord) {
stad.forEach(mysecondfunction);
function mysecondfunction(item) {
if (antwoord.includes(item.value.toLowerCase())) {
item.style.background = "green";
a++;
} else {
antwoord.style.background = "red";
}
}
}
}
}
However, i get the error: item.value is not defined. Within the console, i see that item is a collection of inputs, and not a single input.
Why is this not working?