Sololearn JavaScript course Conditionals and Loops answers

Here are all the questions and answers that I hope will help you learn JavaScript course.
Sololearn JavaScript course Overview answers
Sololearn JavaScript course Basic Concepts answers
Sololearn JavaScript course Functions answers
Sololearn JavaScript course Objects answers
Sololearn JavaScript course Core Objects answers
Sololearn JavaScript course DOM & Events answers
Sololearn JavaScript course ECMAScript 6 answers

14.1 Lesson

The if Statement

Question:

The if Statement
Add the characters that complete the statement:

Answer:

if (var1 > var2) {
  document.write("OK");
}

Question:

The if Statement
What happens if the tested condition is false?

Answer:

The code does nothing and moves to the next section

15.1 Lesson

The else Statement

Question:

The else Statement
The "else" statement is created to do what?

Answer:

Tell JavaScript to execute something if the condition is false

Question:

The else Statement
Fill in the blanks to create a valid if...else statement:

Answer:

var age = 25;
if (age >= 18) {
	alert("Allowed.");
} else {
	alert("Not allowed.");
}

16.1 Lesson

The else if Statement

Question:

else if
What keyword is used to end the "else if" statement?

Answer:

else

Question:

else if
Fill in the blanks to create a valid if...else...if statement:

Answer:

var status = 1;
var msg;
if (status == 1) {
	msg = "Online";
} else if (status == 2) {
	msg = "Away";
} else {
	msg = "Offline";
}

17.1 Lesson

The switch Statement

Question:

Switch
The switch statement can be used to replace…

Answer:

multiple if else statements

Question:

The switch Statement
How many "case" statements are usually used in the "switch" statement?

Answer:

One for each possible answer

Question:

The break Keyword
What’s the output of this code?

var x = 3;
switch (x) {
  case 1:
    document.write(x);
    break;
  case 2:
    document.write(x+2);
    break;
  default:
    document.write(x+5);
}

Answer:

8

Question:

The default Keyword
The "default" statement is used …

Answer:

When no match is found

18.1 Lesson

The For Loop

Question:

Loops
The classic "for" loop consists of how many components?

Answer:

3

Question:

The For Loop
Fill in the blanks to compose a valid for loop:

Answer:

var i = 1;
for (k = 1; k < 10; k++) {
  i += k;
}

Question:

The For Loop
Fill in the blanks to print EVEN values from 0 to 20 using a for loop:

Answer:

var x = 0;
for (; x <= 20; x += 2) {
  document.write(x); 
}

19.1 Lesson

The While Loop

Question:

The While Loop
The result of the condition statement is always:

Answer:

A Boolean value (true or false)

Question:

The While Loop
Fill in the blanks to print x's values from 1 to 5.

Answer:

var x = 1;
while (x <= 5) {
  document.write(x + "<br />");
  x = x + 1;
}

Question:

The While Loop
How many times will the while loop run, if we remove the counting variable increment statement?

Answer:

Infinite

20.1 Lesson

The Do...While Loop

Question:

The Do...While Loop
Apply the "do" and "while" keywords in their corresponding positions.

Answer:

var count=1;
do {
  document.write("hello <br />");
  count++;
}
while (count<=10);

21.1 Lesson

Break and Continue

Question:

Break
The "break" statement:

Answer:

Ends the execution of the loop

Question:

Continue
What’s the output of this code?

Answer:

var sum=0; 
for(i = 4; i < 8; i++) {
  if (i == 6) {
    continue; 
  }
  sum += i;
}
document.write(sum);

22.1 Lesson

Module 3 Quiz

Question:

What’s the output of this code?

var x = 0;
while(x < 6) {
  x++;
}
document.write(x);

Answer:

6

Question:

Fill in the right keywords to test the conditions:

Answer:

switch (day_of_week) {
	case 1:
	case 2:
	case 3:
	case 4:
	case 5:
		document.write("Working Days");
		break;
	case 6:
		document.write("Saturday");
		break;
	default:
		document.write("Today is Sunday");
		break;
}

Question:

Please fill in the right keywords to compose a loop:

Answer:

do {
  document.write(i);
  i++;
}
while (i < 10);