
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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 −
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
Advertisements