I tried to make a function that writes some divs in an HTML document. Everything is working fine but I want to try to change the function declaration from this:
function writeDiv(divDOMelement, numberOfExcercises, numberOfTasksInEx);
To something like this
function writeDiv(divDOMelement, {numberOfExcercises:N, numberOfTasksInEx:[v]})
Just to be clear, the first declaration works perfectly, but when I tried implementing the second one, and changing the function call I received an error.
Here is the full code:
let open = false;
let currentlyOpen;
function writeDiv(divDOMelement, {numberOfExcercises:N, numberOfTasksInEx:[v]}) {
for (let i = 0; i < numberOfExcercises.N; i++) {
// ... didnt include the code that prints the divs on the site just to make it easier to read.
for (let j = 0; j < numberOfTasksInEx.v[i]; j++) {
// ... same as the first loop.
}
}
}
$(document).ready(function () {
writeDiv("#mainDiv", {numberOfExcercises:3, numberOfTasksInEx:[5,2,3]});
});
Just to clarify, this numberOfTasksInEx should be an array, the first element of the array tells me that the first exercise will have that many tasks, the second tells me that the second exercise will have that many tasks, and so on.
The error I am getting:
jQuery.Deferred exception: numberOfExcercises is not defined
Uncaught ReferenceError: numberOfExcercises is not defined
{ numberOfExcercises, numberOfTasksInEx }?