logo CodeStepByStep logo

greeting

Language/Type: PHP string return
Author: Melissa Hovik (on 2018/05/21)

Write a function named greeting that accepts two strings. The first string represents a first name, and the second string represents a surname. Your function should return a greeting message based on these values in the following format:

Hello, First L.!

Where First is the titlecased form of the first string parameter (only the first letter is capitalized) and L is the capitalized first letter of the surname. If the second parameter is empty, the message should instead be in the form Hello!. If the first parameter is empty, the empty string should be returned.

For example, the call greeting("Ash", "Ketchum") should return the string "Hello, Ash K.!" and the call greeting("Mowgli", "") should return the string "Hello, Mowgli!".

You may assume both parameters are of type string.

Function: Write a PHP function as described, not a complete program.

You must log in before you can solve this problem.

Log In

Need help?

Stuck on an exercise? Contact your TA or instructor.

If something seems wrong with our site, please

Is there a problem? Contact us.