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>
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;
}
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;
}
This code is generated by Daniel Davis from https://packagology.com/
Top comments (2)
Just a heads up that you can add highlighting to the code blocks if you'd like. Just change:
... to specify the language:
More details in our editor guide!
Thank you :)