Sending Personalised Messages to User Using JavaScript



Problem

We are required to write a JavaScript function that takes in two strings. The first string specifies the user name and second the owner name.

If the user and owner are the same our function should return ‘hello master’, otherwise our function should return ‘hello’ appended with the name of that user.

Example

Following is the code −

 Live Demo

const name = 'arnav';
const owner = 'vijay';
function greet (name, owner) {
   if (name === owner){
      return 'Hello master';
   }
   return `Hello ${name}`;
};
console.log(greet(name, owner));

Output

Hello arnav
Updated on: 2021-04-17T12:54:04+05:30

243 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements