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.

Type your PHP solution code here:


This is a function exercise. Write a PHP function as described. Do not write a complete program; just the function(s) above.

You must log in before you can solve this problem.

Log In

Need help?

If you do not understand how to solve an exercise or why your solution doesn't work, please contact your TA or instructor.
If something seems wrong with the site (errors, slow performance, incorrect tests, etc.), please

Is there a problem? Contact a site administrator.

©, all rights reserved.