0
0
Javascriptprogramming~10 mins

Logical operators 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 both conditions are true.

Javascript
if (a > 5 [1] b < 10) {
  console.log('Both conditions are true');
}
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 if either condition is true.
Using & is a bitwise operator, not logical.
Using ! negates a condition, not combines two.
2fill in blank
medium

Complete the code to check if at least one condition is true.

Javascript
if (x === 0 [1] y === 0) {
  console.log('At least one is zero');
}
Drag options to blanks, or click blank then click option'
A&
B||
C!
D&&
Attempts:
3 left
💡 Hint
Common Mistakes
Using && requires both conditions to be true, not one.
Using & is a bitwise operator, not logical.
Using ! negates a condition, not combines two.
3fill in blank
hard

Fix the error in the condition to correctly negate the expression.

Javascript
if (! (a === 10 [1] b === 20)) {
  console.log('Condition is false');
}
Drag options to blanks, or click blank then click option'
A||
B!
C&&
D&
Attempts:
3 left
💡 Hint
Common Mistakes
Using && inside negation changes the logic incorrectly.
Using & is a bitwise operator, not logical.
Using ! inside the parentheses is redundant.
4fill in blank
hard

Fill both blanks to create a condition that checks if number is between 5 and 15 inclusive.

Javascript
if (number [1] 5 [2] number [3] 15) {
  console.log('Number is between 5 and 15');
}
Drag options to blanks, or click blank then click option'
A>=
B<
C&&
D||
Attempts:
3 left
💡 Hint
Common Mistakes
Using || instead of && will allow numbers outside the range.
Using > instead of >= excludes 5.
Using <= instead of < includes 15, which may be incorrect.
5fill in blank
hard

Fill all three blanks to create a condition that logs if a string is empty or null.

Javascript
if (str [1] null [2] str [3] '') {
  console.log('String is empty or null');
}
Drag options to blanks, or click blank then click option'
A===
B||
D&&
Attempts:
3 left
💡 Hint
Common Mistakes
Using && will require both conditions to be true, which is impossible.
Using == instead of === can cause unexpected type coercion.
Using & is a bitwise operator, not logical.