0
0
Javascriptprogramming~10 mins

Why conditional logic is needed in Javascript - Test Your Understanding

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 (number [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 '<' checks for negative numbers, not positive.
Using '===' checks for equality, not greater than.
2fill in blank
medium

Complete the code to print 'Even' if the number is divisible by 2.

Javascript
if (number [1] 2 === 0) {
  console.log('Even');
}
Drag options to blanks, or click blank then click option'
A-
B%
C+
D*
Attempts:
3 left
💡 Hint
Common Mistakes
Using '+' or '-' will not check divisibility.
Using '*' multiplies, not divides.
3fill in blank
hard

Fix the error in the condition to check if age is 18 or older.

Javascript
if (age [1] 18) {
  console.log('Adult');
}
Drag options to blanks, or click blank then click option'
A>=
B==
C<=
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' or '<=' checks for younger ages.
Using '==' checks only for exactly 18.
4fill in blank
hard

Fill both blanks to check if a number is between 10 and 20 (inclusive).

Javascript
if (number [1] 10 && number [2] 20) {
  console.log('Between 10 and 20');
}
Drag options to blanks, or click blank then click option'
A>=
B<
C<=
D>
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' for the first blank would exclude 10.
Using '>' for the second blank would exclude 20.
5fill in blank
hard

Fill all three blanks to create an if-else that prints 'Child', 'Teen', or 'Adult' based on age.

Javascript
if (age [1] 12) {
  console.log('Child');
} else if (age [2] 19) {
  console.log([3]);
} else {
  console.log('Adult');
}
Drag options to blanks, or click blank then click option'
A<=
B<
C'Adult'
D>=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '>=' in first blank reverses logic.
Using '<' instead of '<=' in second blank excludes age 19.
Forgetting quotes around 'Adult'.