Class 29 Flashcards

1
Q

What is a program?

A

A set of instructions that you write to tell a computer what to do

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

What is a programming?

A

A task of writing instructions in a language that computer can understand

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

What does variables do?

A

Store information

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

How to create/declare a variable?

A

Use the keyword “let”

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

Conditional syntax

A

if (condition is true) {
//do this
else if (….) {
//do that
else {
// do this then
}

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

Multiple conditions (and)

A

if (name === “Leon” && status === “Balling”) {
do this
}

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

Multiple conditions (or)

A

if (day === “Saturday” || day === “Sunday”) {
It is the weekend
}

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

What are functions?

A

Reusable sets of instructions

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

Functions

A

function yell (word) {
alert(word)
}

yell(“Hello”)

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

What are loops?

A

Repeat an action some number of times

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

What are 3 main types of loops in js?

A

For, while and do while loops

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

For loop

A

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

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

In order to create function in js, what keyword do you need?

A

function

Ex.
function toCelsius(temp) {
… }

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

What are arrays?

A

A data structure to store ordered collection
Array elements are numbered starting with zero
Arrays have many methods to manage the order of elements
Arrays are populated with any type of elements (string, boolean or number)

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

How to create arrays?

A

Through literal notation or a constructor

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

Declaring arrays through literal notation

A

let newArr = []

17
Q

Array iteration

A

Iterate through an array passing in the value and index of each element
newArr.forEach((x,i) => console.log(x))

17
Q

Array length

A

console.log (newArr.length)

18
Q

Explain the reduce method of an array

A

Reduces an array into a single value by passing a callback function on each element of an array

19
Q

Syntax of a reduce method of an array

A

const sum = array1.reduce(
(accumulator, currentValue) => accumulator + currentValue,
initialValue,
)

20
Q

When to use array.reduce()?

A

Sum

21
Q

What does filter method of an array do?

A

The filter() method creates a new array filled with elements that pass a test provided by a function.