Week 2 Flashcards

1
Q

Objects are ‘____’ - ‘____’ pairs

A

key-value

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Write a for loop that counts to 50 by 5.

A

for (i = 0; i < 51; i += 5){
console.log(i)
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are the three parts needed for a for loop?

A
  1. ) Initialization
  2. ) Stopping condition
  3. ) Iteration statement
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q
Write a for in loop that console logs each of the values in the following object.
let pet = { 
name: "Finn", 
breed: "Shiba Inu", 
age: 2, 
goodBoy: true 
};
A
let pet = { 
name: "Finn", 
breed: "Shiba Inu", 
age: 2, 
goodBoy: true 
};
for (item in pet) {
  console.log(pet[item])
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q
How do you invoke or call this function?
function hi( ) {
console.log('Hello')
}
A

hi( )

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Write and invoke a function that counts down from 10 to 0.

A
function countDown( ) {
  for (i = 10; i >= 0; i--)
  console.log(i)
}
countDown( )
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q
Write a for in loop that console logs each item in the following array.
let seasons = ['spring', 'summer', 'autumn', 'winter'];
A
let seasons = ['spring', 'summer', 'autumn', 'winter'];
for (s in seasons){
  console.log(seasons[s])
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Write a function that accepts the parameter food and console logs “My favorite food is …” using the parameter.

A
function favFood(food){
  console.log(`My favorite food is ${food}.`)
}
favFood('sushi')
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Write a function that takes in the parameters crust, sauce, cheese, and topping to build a pizza. Have the function console log your pizza order.

A
function pizza(crust, sauce, cheese, topping){
  console.log(`I would like a pizza with ${crust} crust, ${sauce}, ${cheese}, and ${topping}.`)
}
pizza('thin', 'marinara', 'mozarella', 'olives')
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What does the keyword “Return” do?

A

It brings data out of the function to make it accessible in a wider scope.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

In the following for loop what is i = 1?

for (i = 1; i <= 10; i++) {
console.log(i)
}

A

The initialization

In this case it set the variable of i to 1 initially

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

In the following for loop what is i <= 10?

for (i = 1; i <= 10; i++) {
console.log(i)
}

A

The stopping condition

In this case the for loop will not stop until is is no longer less than or equal to 10

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

In the following for loop what is i++?

for (i = 1; i <= 10; i++) {
console.log(i)
}

A

The iteration statement

In this case it is saying that the variable i will be incremented by one each time to loop runs.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

For the following array write a for of loop that console logs “Super Mario” before each of the items.

let games = [64, “Sunshine”, “Galaxy”, “Odyssey”];

A

let games = [64, “Sunshine”, “Galaxy”, “Odyssey”];

for (game of games) {
console.log(“Super Mario”, game)
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q
What data type is the following:
let colors = ['blue', 'green', 'purple']
A

Array

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q
What data type is the following:
let colors = {'blue', 'green', 'purple'}
A

Object

17
Q
What will be console logged?
let dogs = ['Husky', 'Shiba Inu', 'Beagle', 'Dalmatian']
console.log( dogs[1] )
A

Shiba Inu

18
Q

What index number do arrays start at?

A

0

19
Q

Which array method will append something to the end of an array?

A

.push( )

Example Usage: 
let dogs = ['Husky', 'Shiba Inu', 'Beagle', 'Dalmatian'];
dogs.push('Golden Retriever');
20
Q

Which array method can be used to cut something out of an array and add something else?

A

.splice( )

Example Usage:
let dogs = ['Husky', 'Shiba Inu', 'Beagle', 'Dalmatian']
dogs.splice(0, 1, 'Corgi')
//This will remove Husky and replace it with Corgi
21
Q

The array method .splice( ) takes in three parameters. What is the purpose of each of these three parameters?

A

Array.splice(position, how many to cut, what to add in that location)

22
Q

What array method can be used to remove the last element of an array?

A

.pop( )

Example Usage:
let characters = ['Mario', 'Luigi', 'Yoshi', 'Peach']
characters.pop( )
//This will remove Peach
23
Q

What array method can be used to remove the first item of an array?

A

. shift( )

Example Usage: 
let characters = ['Mario', 'Luigi', 'Yoshi', 'Peach']
characters.shift( )
//This will remove Mario
24
Q
What will happen in the following code:
let characters = ['Mario', 'Luigi', 'Yoshi', 'Peach']
characters.unshift('Bowser', 'Wario')
A

It will add Bowser and Wario to the beginning of the array

[‘Bowser’, ‘Wario’, ‘Mario’, ‘Luigi’, ‘Yoshi’, ‘Peach’]

25
Q

What are the three arguments for a forEach( )

A
  1. ) currentValue = the current element being processed in the array
  2. ) index = the index of the current element being processed
  3. ) array = the array the forEach method was called upon
26
Q
What is the syntax for a forEach( ) that will console log each of the items in this array?
let characters = ['Mario', 'Luigi', 'Yoshi', 'Peach']
A

characters.forEach(c => { console.log(c); })

27
Q

What will this console log?
let food = [‘Pizza’, ‘Pasta’, ‘Hamburger’, ‘Chips’, ‘Ice Cream’]
console.log(food.length)

A

5

28
Q

How would you step through this object and console log ‘fire’?

let pokemon = {
name: 'Bulbasaur',
id: 1,
type: ['grass', 'poison'],
weakness: ['psychic', 'flying', 'fire', 'ice'],
evolvesTo: 'Ivysaur',
description: 'A strange seed was planted on its back at birth. The plant sprouts and grows with this Pokémon.' 
}
A

console.log(pokemon.weakness[2])

29
Q

What does JSON stand for?

A

JavaScript Object Notation