0
0
Javascriptprogramming~10 mins

Else–if ladder in Javascript - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to check if a number is positive.

Javascript
if (num > 0) {
  console.log('Positive');
} [1] {
  console.log('Not positive');
}
Drag options to blanks, or click blank then click option'
Aif (num === 0)
Bif (num < 0)
Celse
Delse if (num === 0)
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'else if' without a condition
Putting a condition after else
2fill in blank
medium

Complete the code to check if a number is zero.

Javascript
if (num > 0) {
  console.log('Positive');
} else if ([1]) {
  console.log('Zero');
} else {
  console.log('Negative');
}
Drag options to blanks, or click blank then click option'
Anum === 0
Bnum = 0
Cnum > 0
Dnum < 0
Attempts:
3 left
💡 Hint
Common Mistakes
Using assignment '=' instead of comparison '==='
Using wrong comparison operators
3fill in blank
hard

Fix the error in the else-if ladder to correctly check if a number is negative.

Javascript
if (num > 0) {
  console.log('Positive');
} else if (num === 0) {
  console.log('Zero');
} else if [1] {
  console.log('Negative');
}
Drag options to blanks, or click blank then click option'
Anum => 0
Bnum < 0
Cnum =< 0
D(num < 0)
Attempts:
3 left
💡 Hint
Common Mistakes
Missing parentheses around condition
Using wrong comparison operators like =< or =>
4fill in blank
hard

Fill both blanks to complete the else-if ladder that checks if a number is positive, zero, or negative.

Javascript
if (num [1] 0) {
  console.log('Positive');
} else if (num [2] 0) {
  console.log('Zero');
} else {
  console.log('Negative');
}
Drag options to blanks, or click blank then click option'
A>
B===
C<
D!=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' instead of '>' for positive check
Using '==' instead of '===' for zero check
5fill in blank
hard

Fill all three blanks to create an else-if ladder that prints if a number is positive, zero, or negative.

Javascript
if (num [1] 0) {
  console.log('Positive');
} else if (num [2] 0) {
  console.log('Zero');
} else if (num [3] 0) {
  console.log('Negative');
}
Drag options to blanks, or click blank then click option'
A>
B===
C<
D!=
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up comparison operators
Using '!=' instead of '===' for zero check