This is with regard to the Quiz tutorial.
The script goes like this,
<script>
var score=0;
var questions = [
['How many moons does Earth have?', 1],
['How many moons does Saturn have?',31],
['How many moons does Venus have?', 0]
];
function askQuestion(question) {
var answer = prompt(question[0],'');
if (answer == question[1]) {
alert('Correct!');
score++;
} else {
alert('Sorry. The correct answer is ' + question[1]);
}
}
for (var i=0; i<questions.length; i++) {
askQuestion(questions[i]);
}
</script>
Everything works fine. But I don't understand the part where we define the function
askQuestion.
i.e.
function askQuestion(question) {
var answer = prompt(question[0],'');
if (answer == question[1]) {
alert('Correct!');
score++;
} else {
alert('Sorry. The correct answer is ' + question[1]);
}
How is the function able to understand "question" when we haven't defined any variable by that name.
We only defined the array "questions".
Please help me understand this.