Default Values for Function Parameters

You are a software developer working on a customizable greeting card application. The application allows users to send greeting messages with custom names and greetings. However, not all users provide a custom name or greeting. You need to ensure that the application works smoothly even when users leave out some information.

  • Declare a function named sendGreeting that takes two parameters: name and greeting.

  • When sendGreeting is called, it should display the message composed of the provided name and greeting. If no parameters are provided, it should default to Guest and Hello, respectively.

Example 1

Input: sendGreeting();
Output: "Guest Hello"

Example 2

Input: sendGreeting("Alice");
Output: "Alice Hello"

Example 3

Input: sendGreeting("Alice", "Hi");
Output: "Alice Hi"

Are you stuck on this problem?

Get detailed, step-by-step solution and improve your JavaScript skills.

  • Detailed Explanation: Each solution comes with a comprehensive explanation, helping you understand the logic and concepts thoroughly.
  • Learn to Write Better Code: Even if you have written the code, discover ways to improve it and adopt best practices.
  • Save Time: Don’t waste hours struggling—get the solution and learn efficiently.
  • Lifetime Access: Get access to lifetime solutions for all problems available
Get the Solution

" I struggled with this problem for hours, but the solution provided here was clear and easy to follow. It helped me understand where I went wrong and improved my coding skills significantly." - Jane D.

If you're not satisfied, I offer a 7-day money-back guarantee.