Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to check if a number is positive.
Javascript
if (num [1] 0) { console.log('Positive'); } else { console.log('Not positive'); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '===' instead of '>' will only check if num equals zero.
Using '<' will check if the number is negative, not positive.
✗ Incorrect
The condition 'num > 0' checks if the number is greater than zero, meaning it is positive.
2fill in blank
mediumComplete the code to print 'Even' if the number is even.
Javascript
if (num % 2 [1] 0) { console.log('Even'); } else { console.log('Odd'); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '!== 0' will check for odd numbers instead of even.
Using '>' or '<' does not correctly check for evenness.
✗ Incorrect
The condition 'num % 2 === 0' checks if the remainder when dividing by 2 is zero, meaning the number is even.
3fill in blank
hardFix the error in the if condition to check if age is at least 18.
Javascript
if (age [1] 18) { console.log('Adult'); } else { console.log('Minor'); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' or '<=' checks for younger ages, not adults.
Using '==' only checks if age equals 18 exactly.
✗ Incorrect
The condition 'age >= 18' checks if age is 18 or older, meaning adult.
4fill in blank
hardFill both blanks to check if a number is between 10 and 20 (inclusive).
Javascript
if (num [1] 10 && num [2] 20) { console.log('Between 10 and 20'); } else { console.log('Outside range'); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '>' or '<' alone excludes the boundary numbers 10 or 20.
Mixing up the operators order can cause wrong logic.
✗ Incorrect
The condition 'num >= 10 && num <= 20' checks if num is between 10 and 20 including both ends.
5fill in blank
hardFill both 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('Teen'); } else { console.log('Adult'); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '>=' in the first condition would reverse logic.
Using '>' in the else if condition would cause wrong grouping.
✗ Incorrect
The code checks if age is less than or equal to 12 for 'Child', less than 19 for 'Teen', else 'Adult'.