Course of Raku / Essentials / Strings / Exercises / Name length

Solution: Name length


Here is the solution to the task:

my $name = prompt 'What is your name? ';
say $name.chars;

🦋 You can find the source code in the file name-length.raku.


Run the program and enter the name.

$ raku exercises/strings/name-length.raku 
What is your name? Alexandra


In this program, we are getting the length of the string by calling the chars method on the $name variable. As the variable contains a string, the method returns the length of it.

Course navigation

Scalar variables / Names of the variables   |   Numbers