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: 17-Apr-2021

180 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements