There are actually different types of loops. And maybe this is about to be a lot to learn at once. But actually, all three of these things are useful together. So, buckle up!
### looping through arrays
In Javascript, an array is an ordered collection of items that you can *iterate* through. There's a fancy coding word. Look, here's how it works:
```javascript
var fruits = ["apple", "banana", "orange"]
for (var fruit of fruits) {
console.log(fruit)
}
// Output:
// apple
// banana
// orange
```
That will print each fruit from the list individually.
If you want a particular item in an array, you can specify it like this. Just keep in mind, the *first* item in the array is number *zero*:
```javascript
var fruits = ["apple", "banana", "orange"]
console.log( fruits[1] )
// Output: banana
```
You can also get the length of an array with the `.length` property:
```javascript
var fruits = ["apple", "banana", "orange"]
console.log( fruits.length )
// Output: 3
```
If you also create an "iterator", then you can do things a certain number of times. Which may be useful for things like:
```javascript
for (let i = 0; i < 5; i = i + 1) {
console.log(i)
}
// Output:
# 1
# 2
# 3
# 4
var fruits = ["apple", "banana", "orange"]
for (let i = 0; i < fruits.length; i = i + 1):
console.log("Index " + String(i) + ": " + fruits[i])
// Output:
// Index 0: apple
// Index 1: banana
// Index 2: orange
```
### objects
You may not want your data in an ordered list, though. Maybe you have information that you'd rather give some names to, but you don't want to make a gazillion variables. In that case, you want a dictionary:
```javascript
var info = { "name": "Ben Hoff", "age": 28, "email": "
[email protected]", "teacher": True }
console.log( info["name"] ) // Output: Ben Hoff
```
See all the data types I put in there? Each of the "keys" needs to be a simple data type like a string or a number, but the "values" could be anything, including complicated things, like lists:
```javascript
var info = {
"name": "Ben Hoff",
"age": 28,
"email": "
[email protected]",
"teacher": true,
"pets": ["Howl", "Cooper", "Hank"]
}
console.log( info["name"] + " has " + String(info["pets"].length) + " pets!")
for (var pet of info["pets"]) {
console.log(pet)
}
// Output:
// Ben Hoff has 3 pets!
// Howl
// Cooper
// Hank
```
You could also, if it becomes relevant, create an array of objects:
```python
questions = [
{
"question": "What's your favorite food?",
"answers": ["Hot Dog", "Hamburger", "Sushi", "Salad"]
},
{...}
]
```
I hope you see where this is going.
## instructions
Update your buzzfeed quiz to store all of your questions and potential answers in a single list of dictionaries. Then, iterate through that list and ask the questions.