Two ways to solve a problem: Function declaration, and anonymous function

PHOTO EMBED

Thu Oct 07 2021 17:47:41 GMT+0000 (Coordinated Universal Time)

Saved by @rahsinc #javascript

function cname(name){
const username = `${name}`;
return username;
}

fname = prompt(`Enter your first name ${name}`)
lname = prompt(`Enter your last name ${name}`)

console.log(`Hello ${fname} ${lname}`);

----------------------------------------------

// Say hello to the user
const sayHello = (firstName, lastName) => `Hello, ${firstName} ${lastName}!`;

// Alternative solution using a function declaration
/* function sayHello(firstName, lastName) {
  return `Hello, ${firstName} ${lastName}!`;
} */

const firstName = prompt("Enter your first name:");
const lastName = prompt("Enter your last name:");
console.log(sayHello(firstName, lastName));
content_copyCOPY