Tracks
/
Elixir
Elixir
/
Exercises
/
High School Sweetheart
High School Sweetheart

High School Sweetheart

Learning Exercise

While completing High School Sweetheart, you'll learn 2 concepts

Instructions

In this exercise, you are going to help high school sweethearts profess their love on social media by generating an ASCII heart with their initials:

     ******       ******
   **      **   **      **
 **         ** **         **
**            *            **
**                         **
**     J. K.  +  M. B.     **
 **                       **
   **                   **
     **               **
       **           **
         **       **
           **   **
             ***
              *

1. Get the name's first letter

Implement the HighSchoolSweetheart.first_letter/1 function. It should take a name and return its first letter. It should clean up any unnecessary whitespace from the name.

HighSchoolSweetheart.first_letter("Jane")
# => "J"

2. Format the first letter as an initial

Implement the HighSchoolSweetheart.initial/1 function. It should take a name and return its first letter, uppercase, followed by a dot. Make sure to reuse HighSchoolSweetheart.first_letter/1 that you defined in the previous step.

HighSchoolSweetheart.initial("Robert")
# => "R."

3. Split the full name into the first name and the last name

Implement the HighSchoolSweetheart.initials/1 function. It should take a full name, consisting of a first name and a last name separated by a space, and return the initials. Make sure to reuse HighSchoolSweetheart.initial/1 that you defined in the previous step.

HighSchoolSweetheart.initials("Lance Green")
# => "L. G."

4. Put the initials inside of the heart

Implement the HighSchoolSweetheart.pair/2 function. It should take two full names and return the initials. Make sure to reuse HighSchoolSweetheart.initials/1 that you defined in the previous step.

HighSchoolSweetheart.pair("Blake Miller", "Riley Lewis")
# => """
#      ******       ******
#    **      **   **      **
#  **         ** **         **
# **            *            **
# **                         **
# **     B. M.  +  R. L.     **
#  **                       **
#    **                   **
#      **               **
#        **           **
#          **       **
#            **   **
#              ***
#               *
# """
Last updated 29 September 2022
Edit via GitHub The link opens in a new window or tab
Elixir Exercism

Ready to start High School Sweetheart?

Sign up to Exercism to learn and master Elixir with 57 concepts, 156 exercises, and real human mentoring, all for free.