For Loops and Arrays - Week 06
Welcome to week 6 of Intro to Web Dev!
Now you know how to use JavaScript, and you know how yo use if
statements, which let you make decisions in your code. This week you’ll learn about for
loops, which let you repeat code multiple times, and arrays, which let you store multiple values in a single variable.
Work through the activities in this page to complete the week!
For Loops
First, watch this video and read through the tutorial to learn about for
loops:
Arrays
Then, watch this video and read through the tutorial to learn about arrays:
Quiz
- In your own words, what is a for loop? When would you use one?
- In your own words, what is an array? When would you use one?
- What does the array function indexOf() do? Note: This function was not mentioned in any of this week’s content. I’m testing that you can research and read about new functions you haven’t seen before. Feel free to use a search engine and resources like W3SChools and MDN to answer this question.
- What is the difference between an if statement and a for loop?
-
What does this code output?
let total = 0; for (let number = 1; number <= 10; number++) { total += number; } console.log(total);
Note: Feel free to copy this code into your editor to see the result!
Project
Now you’ve seen the fundamentals of for
loops and arrays in JavaScript.
To practice these concepts, modify the files in the week-06-for-loops
directory of your project repo.
This video is an example of coding part of this week’s project:
Checklist
- Learn about
for
loops and arrays - Follow the directions in the
week-06-for-loops
directory of your project repo - Push those changes to GitHub and confirm you can see them in your GitHub Pages site
- Get ready to present your work. Make sure your camera and microphone work!