0
0
Javascriptprogramming~10 mins

Comparison 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 a is equal to b.

Javascript
if (a [1] b) {
  console.log("Equal");
}
Drag options to blanks, or click blank then click option'
A!=
B===
C>
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using '==' instead of '===' causes unexpected results.
Using '!=' instead of '==='.
2fill in blank
medium

Complete the code to check if x is greater than 10.

Javascript
if (x [1] 10) {
  console.log("x is greater than 10");
}
Drag options to blanks, or click blank then click option'
A>
B<
C===
D<=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' instead of '>' causes wrong condition.
Using '===' compares equality, not greater than.
3fill in blank
hard

Fix the error in the comparison to check if num is not equal to 5.

Javascript
if (num [1] 5) {
  console.log("Not equal to 5");
}
Drag options to blanks, or click blank then click option'
A=
B===
C!==
D==
Attempts:
3 left
💡 Hint
Common Mistakes
Using '=' instead of '!=='.
Using '==' which checks equality, not inequality.
4fill in blank
hard

Fill both blanks to check if age is between 18 and 30 (inclusive).

Javascript
if (age [1] 18 && age [2] 30) {
  console.log("Age is between 18 and 30");
}
Drag options to blanks, or click blank then click option'
A>=
B<
C<=
D>
Attempts:
3 left
💡 Hint
Common Mistakes
Using '>' instead of '>=' excludes 18.
Using '<' instead of '<=' excludes 30.
5fill in blank
hard

Fill all three blanks to create an object with keys as uppercase names and values as ages greater than 20.

Javascript
const result = people.reduce((acc, person) => {
  if (person.age [3] 20) {
    acc[[1]] = [2];
  }
  return acc;
}, {});
Drag options to blanks, or click blank then click option'
Aperson.name.toUpperCase()
Bperson.age
C>
Dperson.name
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' instead of '>' for age condition.
Using 'person.name' instead of uppercase.
Using wrong value for object property.