CI: Lab, Week 6 – JavaScript Intro Exercise
  • Try to complete the following problems using JavaScript. I want you to use this as an opportunity to try to learn how to solve common JavaScript problems on your own using the power of searching on the internet. Make sure you have your web inspectors open and are viewing the console tab to help debug JavaScript bugs as they happen.

Objectives

  • Practice solving basic JavaScript problems
  • Practice debugging JavaScript code and learning how to search for the answers to common problems on the internet. For example, to a search for javascript how to add two strings together shows us a series of articles that list multiple ways to perform this task, and the pros/cons of each method.

Resources

Assignment

  • Create a new HTML file and create a link to a main.js JavaScript file. Use that JavaScript file to complete each of these tasks in class.
  • For each task, use console.log() to log the result of the task to your DevTools JavaScript console. You will not be able to see the results of your JavaScript code without looking at the DevTools console, so make sure you have it open!

  1. For each of the following items, define a variable to hold the value of the item and log it to the console.
  • A string consisting of your name
  • Your favorite number as an integer
  • Your favorite number as a string
  • A boolean value
  • An array consisting of each of the letters of your first name
  • An array consisting of multiple, different data types. Include at least 3 different data types.
  • Add two strings togethers. The first string is your first name, and the second string is your last name.
  • Add two integers togethers to equal the number 100.
  1. For the array you specified in question 1 (consisting of each of the letters of your first name), log the first item of the array and the last item of the array. When you refer to the last item in the array, try to do it by using the length of the array, rather than manually counting the index of the array.
  1. Log the number of characters in the string ‘supercalifragilisticexpialidocious’ by using the length property.
  1. Log the result of this expression: the length of characters in your first name is equal to the length of characters in your last name.
  1. Create a for loop that loops through the array of characters in your first name and logs each character.
  1. Create a conditional statement that checks to see if the current time is between 7pm and 9:40pm.
  1. Create a conditional statement with multiple conditions that checks to see what the current date is, and logs a unique message for each day of the week.
  1. Create 4 arrays consisting of the following items. Define variables to store each of the 4 arrays.
  • Your favorite 3 restaurants
  • Your favorite 3 things you can’t do during a pandemic
  • Your favorite 3 places in NYC
  • Your favorite 3 movies
  1. Create an array of arrays consisting of the variables from the previous question. Define a variable to hold this array of arrays.
  1. Loop through your array of arrays and log the value of the each item in the array. You should be looping through 4 things, and each value you log should be an array. For example, the first item logged would be an array containing 3 restaurants, the second item would be an array containing 3 animals, etc.
  1. Create a nested for loop that loops through the array of your favorite items and logs each individual item. The first loop should log the category of the item, while the nested loop should log each individual item in that category.