Hello, Everyone
I recently picked up javascript, and I am starting to build projects in javascript. While I was studying a particular tutorial on building javascript quiz from this website : https://simplestepscode.com/javascript-quiz-tutorial/
I noticed something strange, noticed that the object is myQuestion
But when you go through the for loop, it is written as:
for(var i=0; i<questions.length; i++)
shouldn’t it be:
for(var i=0; i<myQuestions.length; i++)
If the the object array is myQuestions, shouldnt it be placed inside the for loop.
I understand the entire program, but this is part that is confusing
you pass the global object as function argument: generateQuiz(myQuestions, quizContainer, resultsContainer, submitButton); (step 4: put it all together)
so inside the function you just use questions, and in this way the function is completely reusable, you can have a different object, put that in the function call, and it works anyway
you use function parameters as arrays when they have an array passed in
" you pass the global object as function argument: generateQuiz(myQuestions, quizContainer, resultsContainer, submitButton); (step 4: put it all together)"
Okay now I understand, but why not pace “myQuestions” as a function parameter at the beginning of the code.