Conditional code Flashcards

1
Q

What is the basic building block of the “IF” statement in javascript

A

if ( . . . ) { . . .

}

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

( . . . ) represents ____________

A

If (The condition is true) {
Then do what is between this
}

( . . . ) = If this condition is true

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

{ . . . } represents _____________

A

If (The condition is true) {
Then do what is between this
}

{ . . . } = then do what is between these curly braces

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

( 1 )

A

Parentheses

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

[ 1 ]

A

brackets, oftentimes called square brackets

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

{ 1 }

A

curly braces

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

what is the purpose if braces, parenthesis, and brackets in coding?

A

They mark where a type of statement begins and ends

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

are braces, parenthesis, and brackets sometimes interchangeable?

A

NO, never change them nigga

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

brackets, braces, and parenthesis are always found in….

A

PAIRS

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

ALL conditions must boil down to….

A

true or false

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

how do you check for quality in a javascript condition?

A

==

double equal sign

If ( a==99) { execute this command
}

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

why is == a quality check and not one equal sign?

*Why use:
If ( a==99) { execute this command
}

and NOT

If ( a=99) { execute this command
}

A

because 1 equal sign SETS a value. a==99 means CHECK if a==99, and a=99 means a IS 99

If ( a==99) { execute this command
}

If ( a=99) { execute this command
}

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

how do you check inequality? that is check if a is NOT some variable

A

If ( a!=99) { execute this command

}

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

code block

A

several statements all grouped together, normally with the use of braces, parenthesis, or brackets.

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

how many lines if “IF” statements can javascript understand?

A

theoretically, infinite…

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

Why don’t we want to use too many if statements? What are other options?

A

It can become difficult for a human to understand. We can use functions or switches instead.

17
Q

equality is used

A

when we want to check one variable against another

If ( balance == 10000) {Some command
}

the == operates as the equality operator

18
Q

single “=” equal sign is known as the ___________ operator

A

assignment operator

you are telling javascript what you want some variable to be

19
Q

double “==” equal sign is known as the ___________ operator

A

equality operator

you are asking javascript to check if the value of one variable is the same as another and to produce a true or false

20
Q

triple “===” equal sign is known as the ________ operator

A

strict equality operator

a more “strict” version of ==

21
Q
var a = 123;
var b = "123";
if ( a == b ) {
   alert("Yes, they ARE equal");
} else {
   alert("No, they're NOT equal");
}

**Will this alert yes, or no?

*NOTE double equal sign

A

Yes

123 is the same as “123”

22
Q
var a = 123;
var b = "123";
// equality check
if ( a === b ) {
   alert("Yes, they ARE equal");
} else {
   alert("No, they're NOT equal");
}

**Will this alert yes, or no?

*NOTE triple equal sign

A

No

123 is a number and “123” is a character string

23
Q

How do you do the not equal to operator to check an equality?

A

(a != b)

24
Q

how do you use the strictly not equal to operator?

A

(a !== b)

25
Q

how do you perform an “AND” operator in javascript?

A

&&

double ampersand

26
Q

how do you write a condition for a has to equal b, and c has to equal d

A

if ( a===b && c===d) {…

{

27
Q

how to you write an OR operator in javascript?

A

||

double vertical line

28
Q

what is the difference between :

if ( a===b && c===d) {…
{

and

if ( (a===b) && (c===d) ) {…
{

A

no difference, trick question

29
Q

rewrite using SWITCH:

var grade = “Premium”;

if ( grade === "Regular") {
     alert("It's $3.15");
}
if ( grade === "Premium") {
     alert("It's $3.35");
}
if ( grade === "Diesel") {
     alert("It's $3.47");
}
A

var grade = “Premium”;

switch (grade) {

case “Regular”:
alert ( “It’s $3.15 “ );
break;

case “Premium”:
alert ( “It’s $3.35” );
break;

case “Diesel”:
alert ( “It’s $3.47” );
break;

default:
alert(“Not valid grade”);
}