Course of Raku / Essentials / Control flow 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

Ternary operator   |   Plural ending

Translations of this page: EnglishDeutschEspañolItalianoLatviešuNederlandsБългарскиРусскийУкраїнська