Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to assign 'even' if number is divisible by 2, otherwise 'odd'.
Ruby
result = number % 2 == 0 ? [1] : 'odd'
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Putting 'odd' before the colon instead of 'even'.
Forgetting quotes around the string.
✗ Incorrect
The ternary operator checks if number is divisible by 2. If true, it assigns 'even', else 'odd'.
2fill in blank
mediumComplete the code to assign 'adult' if age is 18 or more, otherwise 'minor'.
Ruby
status = age >= 18 ? [1] : 'minor'
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'child' or 'teen' instead of 'adult'.
Confusing the true and false parts.
✗ Incorrect
If age is 18 or more, the ternary operator assigns 'adult', else 'minor'.
3fill in blank
hardFix the error in the ternary operator to assign 'positive' if num > 0, else 'non-positive'.
Ruby
label = num > 0 ? [1] : 'non-positive'
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Missing quotes around 'positive'.
Using a variable name instead of a string.
✗ Incorrect
The true part must be a string 'positive' with quotes, not a bare word.
4fill in blank
hardFill both blanks to assign 'even' if n is divisible by 2, else 'odd'.
Ruby
result = n % 2 [1] 0 ? 'even' : [2]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '!=' instead of '=='.
Swapping 'even' and 'odd' in the false part.
✗ Incorrect
The condition checks if n % 2 equals 0. If true, 'even' else 'odd'.
5fill in blank
hardFill all three blanks to assign 'positive', 'negative', or 'zero' based on the value of val.
Ruby
label = val > 0 ? [1] : val < 0 ? [2] : [3]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up the order of conditions.
Forgetting quotes around strings.
✗ Incorrect
Nested ternary checks val > 0 for 'positive', val < 0 for 'negative', else 'zero'.