It's evident from the book's example that you want jlliagre
's solution, not mine. The following details may help, though.
Whenever you call a function in your shell script, it's as though you were calling a separate shell script. The function you call, just like any shell script, has a return code and can do output to standard output and standard error.
's answer and the book use the return code. This is excellent for making decisions, which is the way the book uses it.
If you ever want a more complicated return value, though, use standard output. "More complicated" can mean alphanumeric strings, for example. The return code is limited to integers between 0 and 255.
And if you want to debug your function, send debugging data to standard error, not standard output:
echo "got to this point in the code" 1>&2