Create an HTML file named index.html and a JS file named main.js in this folder. Link them with a script tag. In main.js, work through the following tasks.
Convert these lists of things into JavaScript arrays.
For example...
- Cheese
- Chocolate
- Olives
- Anchovies
Would become...
const favoriteFoods = ["Cheese", "Chocolate", "Olives", "Anchovies"];
👉 You do the rest!
- Tiny Dancer
- Running Up That Hill
- Don't Stop Moving
- Tragedy
- Crazy Horses
- 1
- 2
- 4
- 8
- 16
- 32
- 64
- Name is Chris; special skill is changing lives.
- Name is Lizzie; special skill is being friendly.
- Name is Ben; special skill is code rapping.
- Name is Tao; special skill is hand raising.
- Name is Liz; special skill is crochet.
- Name is Patrick; special skill is Call of Duty.
- Name is Tim; special skill is analogies.
- Name is James; special skill is friendship.
- Name is Joseph; special skill is being positive.
- Name is Max; special skill is papier-mâché.
let options = [
"Jan",
"Feb",
"Mar",
"Apr",
"May",
"Jun",
"Jul",
"Aug",
"Sep",
"Oct",
"Nov",
"Dec",
];
Using bracket notation and the correct index, for each person...
👉 Console.log the month in which you were born.
👉 Console.log the month your mother was born.
👉 Console.log your favorite month.
We can use the useful loops we learned to access the items in an array.
let englishNumbers = ["one", "two", "three", "four", "five"];
👉 Declare an index variable and assign it the value of 0.
👉 In a while loop, console.log the array item at the current index and add 1 to the index variable.
👉 Have the while loop run until the index is equal to or greater than the array's length property.
👉 Refactor task three to use a for loop instead of a while loop.
let words = ["ben", "ha", "spla", "fa", "ca", "dra"];
// for loop goes here
console.log(words);
👉 Use a for loop to iterate over the words array and add the letter t to the end of each word ("ben" becomes "bent", "ha" becomes "hat", etc.).
👉 Explore arrays more. For example, you could...
- Create nested arrays and objects.
- Create functions that take in information and use that information to create or change arrays.
- Find a way to write a function that gives back a random item in the array.
- Look online in documentation (for example, MDN or W3Schools) about arrays in JavaScript. Can you find anything new or surprising?