Part 4- A Smarter Way to Learn JavaScript Flashcards

1
Q

In this piece of code, what does: var i = 0 mean?

for (var i = 0; i<=4; i++) {
//code to run goes here
}

A

It’s the “counter”. It changes in each iteration so that eventually the FOR loop will end.

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

In this piece of code, what does i<=4 mean?

for (var 1 = 0; i<=4; i++) {
//code to run goes here
}

A

*it’s the “loop limiter”

*it tells you how many iterations will run.

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

In this piece of code, what does i++ mean?

for (var 1 = 0; i<=4; i++) {
//code to run goes here
}

A

*it’s the “incrementor” (my name)

*it adjusts the variable i for the next iteration

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

What’s the format of the first line of a FOR loop?

A

for (var i = 0; i<=4; i++) {

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

How would you code to loop through a test repeatedly?

A

FOR loop with an embedded IF loop:

for (var 1 = 0; i<=4; i++) {
if (x === y) {
//do this code
}
}

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

What’s the point of a FOR loop? What does it do?

A

It repeats the same code over and over, each time with a different value.

This is looping, AKA iteration.

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

What if you want to FOR loop your way through each value in an array, but you don’t know how long the array is?

A

*set the second part of a FOR loop to this: i < arrayName.length.

*Or you can set up a variable equal to the length of the array:
var numElements = arryName.length, then you put it in the “i <” spot (second part of a FOR loop):
for (var i = 0; i < numElements; i++)

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

How do you set up a variable equal to the length of an array?

A

var x = arrayName.length;

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

Do Boolean use quotation marks like a string?

A

No. It’s just true and false

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

What is a flag and how do you use it in looping?

A

*a flag is a variable that starts as one value, then changes value if something happens.

*in a FOR loop, you might set a flag to a Boolean value so that when the loop matches something, it returns the other Boolean value

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

What’s a BREAK

A

break;

A keyword that ends your loop. Put it in your code so if you get the right answer, it doesn’t keep looping and looping.

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

What is an assignment operator?

A

= += -=
*= /= %= :

*An assignment operator is the code used to assign a new value to a variable, property, event, etc.

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

Can you nest FOR loops?

A

Yes. You can use a j for the first nested loop, k for the next, etc etc.

Think of the nested loop as the second hand and the original loop as the minute hand. The nested loop will go through all of its iterations, then the original loop will increment its variable. Then the nested loop will go through all its iterations again, etc etc

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

What are the two types of control flow statements in JavaScript?

A

*Conditional

*Iterative (Looping)

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

Change letters to lowercase?

A

var str1 = str1.toLowerCase();

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

Can slice() be used on a string?

A

Yes. You can use it directly on the string, or on a variable that represents the string.

17
Q

What does this do?
text.indexOf(“Apple”);

A

*it looks through the variables text
*it finds the index number of the first character of the string apple

18
Q

What is text.indexOf( ); used for?

A

Finding a phrase in a body of text. It only finds the first character of the phrase, but that’s all the info you need to create code to modify the phrase.

19
Q

What is one drawback of text.indexOf()?

A

It only finds the FIRST instance and not other instances. To find other instances, you would have to loop.

20
Q

How do you find the last place a phrase appears in a text?

A

text.lastIndexOf(“phrase you’re looking for”):