Skip to content

Instantly share code, notes, and snippets.

@rogerwschmidt
Last active May 4, 2017 00:52
Show Gist options
  • Save rogerwschmidt/4c718fc1b18a23f150705d047deaaefd to your computer and use it in GitHub Desktop.
Save rogerwschmidt/4c718fc1b18a23f150705d047deaaefd to your computer and use it in GitHub Desktop.

Arrays

Objectives

Create an array and access array elements using JS.

CFU

Create an array literal that stores your three favorite cities as literal strings.
Print out each element individually.

Stretch:
Use a for loop to print out all the items in turn.

Add, modify, and remove elements in an array.

CFU

Given the following array 

var cities = ['Boulder', 'Lincoln', Chicago']

- Add a city to the end of the array
- Change 'Boulder' to 'Denver'
- Remove 'Lincoln'

Name and describe the 4 methods used to add and remove elements from the front and back of an array.

CFU

What are the 4 methods used to add and remove elements from the front and the back of an array?

Use the concat method to join 2 or more arrays.

CFU

Given the following arrays:

var east = ['Boston', 'New York', 'Philadelphia']
var west = ['San Diego', 'Portland', 'San Fransisco']

Use concat to join both arrays and store the result in a new variable.

Join arrays into strings and split strings into arrays.

CFU

Given the following string:

var myFavoriteIceCreamFlavor = 'Chocolate Chip'

Split the string and store the resulting array in a new variable.

and, given the following array:

var songTitle = [1,2,3,4,5,6]

Join the array into a string with each array element being separated by a dash.

Use Math.floor() and Math.random() to generate random integers.

CFU

Generate a random number between 1 and 100, store the number into a new variable
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment