Course of Raku / Essentials / Creating and calling functions / Exercises / Odd or even
Solution: Odd or even
The function’s body is quite small, which is a valid reason to omit both the return
routine and the semicolon at the end of the line.
Code
Here is the solution:
sub f($n) {
$n %% 2 ?? 'Even' !! 'Odd'
}
say f(10);
say f(5);
say f(0);
say f(3);
🦋 Find the program in the file odd-or-even.raku.
Output
$ raku exercises/functions/odd-or-even.raku
Even
Odd
Even
Odd
Next exercise
Course navigation
← Associative data types / Interpolating hashes | More about functions →
Translations of this page: English • Deutsch • Español • Italiano • Latviešu • Nederlands • Български • Русский • Українська