This course has been updated! We now recommend you take the Complete Intro to Web Development, v3 course.

Check out a free preview of the full Introduction to Web Development course:
The "Exercise 6: Arrays" Lesson is part of the full, Introduction to Web Development course featured in this preview video. Here's what you'd learn in this lesson:

In this exercise, you will work with an array by accessing an item within it.

Get Unlimited Access Now

Transcript from the "Exercise 6: Arrays" Lesson

[00:00:00]
>> [MUSIC]

[00:00:04]
>> Nina Zakharenko: Can you guys read that? It says, My favorite fruit is undefined. And that's because we have declared this variable. But we don't have anything in it. So just a super quick exercise. Set the variable favoriteFruit to your favorite item in the array. Use that square bracket notation.

[00:00:23] And then.
>> Nina Zakharenko: It should update automatically and print out my favorite fruit is and your favorite fruit
>> Nina Zakharenko: So would need type along with you guys real quick.
>> Nina Zakharenko: My favorite fruit is an orange, so I'm gonna do fruits and 1.
>> Nina Zakharenko: So I actually don't need this because I declared that above.

[00:01:50]
>> Nina Zakharenko: Sorry, for those CodePen you're gonna have to click on Run one more time.
>> Nina Zakharenko: So everyone have their favorite fruit coming up? Okay, so what's gonna happen if we try to access fruit number 99? We get undefined again, but if we open up our JavaScript console.
>> Nina Zakharenko: We'll just copy and paste this here.

[00:02:39]
>> Nina Zakharenko: So we try minus one, yeah, there's nothing in that spot so nothing going on