Week 6 - Wednesday, May 26th
Last updated
Last updated
// Create an array named colors that contains five different
// names of colors as strings.
// Access the first color in the array and print it
// to the console using console.log()
// Now do the same with the third color in the list.
// Write one line of code that changes the value of
// the last color in the list to "ultraviolet"
// (overwriting the previous value)
// Create a new variable called fourthColor and set it
// equal to the fourth color in the list.
// Add another color to the end of the list.
// Search on google for "javascript array add element to end"
// if you don't remember the name of the function,
// or how to call it.
// Add another color to the beginning of the list.
// Search on google for "javascript array add element to beginning"
// if you don't remember the name of the function,
// or how to call it.
// Print the length of the array to the console with console.log()
// Remove the last color from the end of list,
// and then print the length of the array to the console
// one more time.
// Search on google for "javascript array remove element from end"
// if you don't remember the name of the function,
// or how to call it.
// Write a for loop to iterate through every color
// in the array and print each color's value to the console.
// Copying from that loop you just wrote, modify it to
// print every color's value and every color's index in
// this format:
// 0, blue
// 3, purple
// etc
// Create a variable named lastColor that will always
// point to the last element of the colors array,
// no matter how many colors are in the list.
// Get the last color using the variable and print it to the console.
// (Hint: make use of the array's length property