Preview:
const name = prompt("What's your name?"); // ask for user's name

if (name) {
  const greeting = `Hi ${name}! How can I assist you today?`;
  console.log(greeting);
}

// Example function that uses the user's name in the response
function sayThanks() {
  if (name) {
    console.log(`Thank you, ${name}! I'm happy to help.`);
  } else {
    console.log("Thank you! I'm happy to help.");
  }
}
This code prompts the user to enter their name using the prompt() method and stores the result



downloadDownload PNG downloadDownload JPEG downloadDownload SVG

Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!

Click to optimize width for Twitter