DEV Community

Zoya Khan
Zoya Khan

Posted on • Edited on

1

HTML Code for Random Name Generator

You can use this code to make your own random name generator for free:

<!DOCTYPE html>
<html>
  <head>
    <title>Random Name Generator</title>
    <link rel="stylesheet" href="style.css">
  </head>
  <body>
    <h1>Random Name Generator</h1>
    <p id="name"></p>
    <button onclick="generateName()">Generate</button>
    <script src="script.js"></script>
  </body>
</html>
Enter fullscreen mode Exit fullscreen mode
body {
  font-family: Arial, sans-serif;
  text-align: center;
}

h1 {
  font-size: 2rem;
}

p {
  font-size: 1.5rem;
  margin-top: 2rem;
}

button {
  font-size: 1.2rem;
  padding: 0.5rem 1rem;
  margin-top: 2rem;
  border: none;
  background-color: #007bff;
  color: #fff;
  border-radius: 5px;
  cursor: pointer;
}

button:hover {
  background-color: #0062cc;
}
Enter fullscreen mode Exit fullscreen mode
function generateName() {
  const names = [
    "Alice", "Bob", "Charlie", "David", "Eve", "Frank",
    "Grace", "Heidi", "Ivan", "Judy", "Kevin", "Linda"
  ];

  const index = Math.floor(Math.random() * names.length);
  const name = names[index];

  const nameElement = document.getElementById("name");
  nameElement.innerText = name;
}
Enter fullscreen mode Exit fullscreen mode

This code is generated by Daniel Davis from https://packagology.com/

AWS GenAI LIVE image

Real challenges. Real solutions. Real talk.

From technical discussions to philosophical debates, AWS and AWS Partners examine the impact and evolution of gen AI.

Learn more

Top comments (2)

Collapse
 
szabgab profile image
Gabor Szabo

Just a heads up that you can add highlighting to the code blocks if you'd like. Just change:

code block with no colors example

... to specify the language:

code block with colors example

More details in our editor guide!

Collapse
 
zoyakhanblogger profile image
Zoya Khan

Thank you :)

Some comments may only be visible to logged-in visitors. Sign in to view all comments.

Billboard image

Create up to 10 Postgres Databases on Neon's free plan.

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Try Neon for Free →

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay