if statements nested Flashcards

1
Q

An alternative to using && to test multiple conditions in a single if statement is ______ ifs.

A

nested

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

You communicate the nesting to JavaScript with the placement of what two characters? Don’t type a space between them.

A

{}

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

How do you make nested ifs readable? Answer with 1 lower-case verb.

A

indent

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

This is the first line of an if statement.
if (a !== b) {
Enter the first 6 characters of the next line, which is a second-level if.

A

if (

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

Code the first line of an if statement that’s followed by the first line of a nested if. If a equals b, then if c doesn’t equal d….

A

if (a === b) {

if (c !== d) {

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

Code an if statement enclosing a nested if. If a equals 1, then if c equals “Max”, then display an alert that says “OK”.

A
if (a === 1) {
  if (c === "Max") {
    alert("OK");
  }
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q
if (a === 1) {
  if (c === "Max") {
    alert("OK");
  }
}
Code the first line of an if statement that avoids the nesting above by testing for multiple conditions.
A

if (a === 1 && c === “Max”) {

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

if (a !== 0 && b > 1) {

Code the first lines of nested if statements that test the same conditions as the above code.

A

if (a !== 0) {

if (b > 1) {

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

if (a !== 0 && b > 1 && c < 1) {

Code the first lines of nested if statements that test the same conditions as the above code.

A

if (a !== 0) {
if (b > 1) {
if (c < 1) {

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

Code nested if statements that test whether a first variable equals a particular number and whether a second variable equals another number. If so, display an alert message.

A
if (a === 0) {
  if (b === 1) {
    alert("OK");
  }
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Code nested if statements that test whether a first variable equals a second variable, whether a third variable doesn’t equal a fourth variable, and whether a fifth variable is greater than a sixth variable. If all tests pass, assign a number value to a seventh variable, which hasn’t been declared beforehand.

A
if (a === b) {
  if (c !== d) {
    if (e > f) {
      var g = 1;
    } 
  }
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly