educative.io

Quiz question javascript array students vs student to access array element

Issue with a quiz question.
Asks if student[0] (student singular)
will access the first element in the
students array (students plural)


Course: Learn HTML, CSS, and JavaScript from Scratch - Free Interactive Course
Lesson: Data Structures: Arrays - Learn HTML, CSS, and JavaScript from Scratch

Hi @Carol_Enderlin !!
In this question
Q: The following statement:

student[0];

will access the first element in the array.

A)

True

B)

False
The correct answer is:

A) True

Explanation:

In the given explanation, the array is defined as:

var students = ["Mary", 10, "Barbara", 11, "David", 12, "Alex", 11];

Arrays in JavaScript are zero-indexed, which means that the first element of the array has an index of 0, the second element has an index of 1, and so on.

So, when you use students[0], you are accessing the first element of the array, which is “Mary”. This is why the statement student[0]; is true; it will indeed access the first element in the array.

The quiz statement is asking whether the statement student[0]; will access the first element in the array, and the correct answer is “True.”
I hope it helps. Happy Learning :blush:

You are missing my point that “student” does not equal “students”, a simple typo where the s at the end of students is missing.

I understand your concern now. It appears that there is a typo in the quiz question where “student” is mentioned instead of “students”.This will be fixed soon.
Thanks for pointing it out. Happy Learning :blush:

1 Like