Core Interaction

JavaScript Intro Exercise

Friday, 3/ 6 – Lab

Overview

Divide into groups of 3 or 4. 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.
  2. 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.

  3. Log the number of characters in the string ‘supercalifragilisticexpialidocious’ by using the length property.

  4. 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.

  5. Create a conditional statement that does the following:
    • If all students are here log a message that says all the students are in class
    • Otherwise, log a message that says not everyone is here
  6. Create a for loop that loops through the array of characters in your first name and logs each character.

  7. Create a conditional statement that checks to see if the current time is between 7pm and 9:40pm.

  8. Create a conditional statement with multiple conditions that checks to see what the current date it is, and logs a unique message for each day of the week.

  9. Create 4 arrays consisting of the following items. Define variables to store each of the 4 arrays.
    • Your favorite 3 restaurants
    • Your favorite 3 animals
    • Your favorite 3 places in NYC
    • Your favorite 3 pokemon
  10. Create an array of arrays consisting of the variables from the previous question. Define a variable to hold this array of arrays.

  11. 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.

  12. 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.