Course of Raku / Essentials / Conditional checks / Ternary operator

Quiz — Ternary operator

Fill in the gaps in the program:

. my $color = prompt 'What colour is it? ';
?? say $color eq 'blue' ␣␣
!!     'This is a sky!' ␣␣
.     'I need more information.';

Comment

The Rakudo compiler has a special error message for the most common error you can make when using the ternary operator in Raku.

===SORRY!=== Error while compiling /Users/ash/raku-course/t.raku
Unsupported use of ?  and : for the ternary conditional operator.  In
Raku please use: ??  and !!.
at /Users/ash/raku-course/t.raku:2
------> say $color eq 'blue' ?⏏ 'This is a sky!' : 'I need more informa

Course navigation

Conditional checks / Comparing strings   |   💪 Exercises: Conditional checks