Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to assign 'adult' if age is 18 or more, otherwise 'minor'.
Javascript
const status = age [1] 18 ? 'adult' : 'minor';
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '==' instead of '>=' causes wrong classification.
Using '<' reverses the logic.
✗ Incorrect
The ternary operator checks if age is greater than or equal to 18 to assign 'adult'.
2fill in blank
mediumComplete the code to assign 'even' if number is divisible by 2, else 'odd'.
Javascript
const type = (num % 2) [1] 0 ? 'even' : 'odd';
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '!=' causes odd numbers to be classified as even.
Using '>' or '<' is incorrect for equality check.
✗ Incorrect
The ternary checks if remainder is exactly 0 to determine even numbers.
3fill in blank
hardFix the error in the ternary condition to check if score is passing (>= 60).
Javascript
const result = score [1] 60 ? 'pass' : 'fail';
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' reverses the pass/fail logic.
Using '==' only passes if score is exactly 60.
✗ Incorrect
The condition must check if score is greater than or equal to 60 to pass.
4fill in blank
hardFill both blanks to create a ternary that returns 'positive' if num > 0, else 'non-positive'.
Javascript
const sign = num [1] 0 ? 'positive' : [2];
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<=' in first blank reverses the logic.
Using 'negative' instead of 'non-positive' changes meaning.
✗ Incorrect
The ternary checks if num is greater than 0; if not, it returns 'non-positive'.
5fill in blank
hardFill all three blanks to create a ternary that returns uppercase key if value > 10, else lowercase key if value > 5, else 'low'.
Javascript
const label = value [1] 10 ? key.[2]() : (value [3] 5 ? key.toLowerCase() : 'low');
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<=' instead of '>' changes the logic.
Using 'toLowerCase' in second blank returns lowercase instead of uppercase.
✗ Incorrect
The first condition checks if value is greater than 10, then returns uppercase key. The second checks if value is greater than 5, then returns lowercase key. Otherwise, returns 'low'.