WFwalker.forrester

home / projects / what is greetr

Question

What is Greetr?

A small JavaScript library Walker Forrester wrote that greets people by name in 21 languages.

What is Greetr? Greetr is a small JavaScript library that Walker Christian Forrester wrote. Given a first name, a last name and an optional language, it builds a formal or an informal greeting. Its list of supported languages has 21 entries, from English and Spanish to Hausa, Swahili and Indonesian.

How it works

Greetr is built like a miniature jQuery. You call G$('first', 'last') without the new keyword, set the language with setLang, and chain the next call on with a dot. The language list and the greetings sit privately inside a closure, the shared methods live once on the prototype, and a language that isn't supported stops with an "Invalid language" error. It can write the greeting into a web page with jQuery or with plain JavaScript.

Building a library like Greetr is a well-known exercise from Anthony Alicea's course JavaScript: Understanding the Weird Parts. Walker's version goes past the basics with its 21 languages. The code is public on GitHub at walkforr/greeterLibrary, and there is a live demo at walkforr.github.io/greeterLibrary.

Related