About 2 hours
JavaScript is used on the frontend of almost every website. It’s also a widely-used scripting language that be used on the backend as well. The JavaScript lessons set a solid foundation in JavaScript basics so we can use the language in more robust ways in later lessons.
Participants will be able to:
Video walkthrough of lesson slides JavaScript 4 - Loops (20 min)
Read through lesson slides JavaScript 4 - Loops
You’ll get stuck in an infinite while loop if you don’t increment or decrement the counter variable.
When using a for loop, remember that list indexing starts at zero!
Work through this lesson on JS loops (about 30 min): https://www.codecademy.com/courses/introduction-to-javascript/lessons/loops/exercises/loops?action=resume_content_item
Techtonica staff will assign pairs.
Open REPL.it.
Activity 1 - Vacation Time!
Write a function called printVacations
whose input is an array of arrays. Each sub-array should have two strings as elements: The 0th element should be a person’s name and the 1st element should be that person’s most desired vacation destination. Include a minimum of 3 sub-arrays in your input array, like so:
[ ['Tammy', 'Tahiti'], ['Erin', 'Banff, Alberta, Canada'], ['Janet', 'London'] ]
Your function should print each person’s name and desired destination in a complete sentence, like this:
Tammy really wants to go to Tahiti.
Erin really wants to go to Banff, Alberta, Canada.
Janet really wants to go to London.
Activity 2 - Vacation Choices
Follow the prompt for Activity #1, but use this format for the input array instead:
[ ['Tammy', ['Tahiti', 'Bali', 'Hawaii']], ['Erin', ['Banff, Alberta, Canada', 'Iceland']], ['Janet', ['London', 'Hogwarts']] ]
The output should look similar to this:
Tammy is willing to go to Tahiti, Bali or Hawaii.
Erin is willing to go to Banff, Alberta, Canada or Iceland.
Janet is willing to go to London or Hogwarts.
For Loops
While Loops
let ourArray = [];
let i = 0;
while(i < 5) {
ourArray.push(i);
i++;
}
console.log(ourArray)