0
0
Javascriptprogramming~10 mins

Nested conditional statements 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 [1] 0) {
  console.log('Positive number');
}
Drag options to blanks, or click blank then click option'
A<
B>
C===
D!==
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' instead of '>' will check for negative numbers.
Using '===' checks for equality, not greater than.
2fill in blank
medium

Complete the code to check if a number is positive and even.

Javascript
if (num > 0) {
  if (num [1] 2 === 0) {
    console.log('Positive even number');
  }
}
Drag options to blanks, or click blank then click option'
A%
B/
C*
D-
Attempts:
3 left
💡 Hint
Common Mistakes
Using division / instead of modulus %.
Using multiplication or subtraction operators incorrectly.
3fill in blank
hard

Fix the error in the nested condition to check if a number is negative and odd.

Javascript
if (num [1] 0) {
  if (num % 2 !== 0) {
    console.log('Negative odd number');
  }
}
Drag options to blanks, or click blank then click option'
A<
B!==
C>
D===
Attempts:
3 left
💡 Hint
Common Mistakes
Using '>' instead of '<' to check for negative numbers.
Using equality operators instead of comparison.
4fill in blank
hard

Fill both blanks to check if a number is zero or positive and even.

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

Fill all three blanks to check if a number is positive, even, and less than 100.

Javascript
if (num [1] 0) {
  if (num [2] 2 === 0 && num [3] 100) {
    console.log('Positive even number less than 100');
  }
}
Drag options to blanks, or click blank then click option'
A>
B%
C<
D===
Attempts:
3 left
💡 Hint
Common Mistakes
Using division instead of modulus for even check.
Using '>=' instead of '>' for positivity.
Using '>' instead of '<' for less than 100.