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

Course navigation

Odd or even   |   Recursive factorial

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