I've developed a random name generator code that is powered by both CSS and JavaScript. Currently, the code allows me to input any name - regardless of gender - press the generate button, and receive a randomly generated first and last name. However, I now wish to have distinct buttons for male, female, and unisex names.
In my attempts to achieve this, I created separate div IDs for male and female names, duplicated the JavaScript section, and modified the code segments to 'femalename' and 'malename'. Unfortunately, this approach compromised the formatting and caused both divs to generate a name whenever any of the generate buttons were clicked.
<!DOCTYPE HTML>
<html xmlns='http://www.w3.org/1999/xhtml'>
<head>
<title>Random Name Generator</title>
<meta charset='utf-8' />
<style type='text/css'>
#name {
color : #444;
font : bold 51px times, Times New Roman, times-roman, georgia, serif;
letter-spacing : -2px;
line-height : 44px;
text-align : center;
text-transform: uppercase;
}
#refresh {
font : normal 11px Gill Sans, Verdana;
letter-spacing : 2px;
line-height : 14px;
text-align : center;
text-transform : uppercase;
}
a {
color : #666;
}
a:hover {
color : #999;
}
</style>
</head>
<body>
<script type='text/javascript'>
first = ['abbie ', 'abby ', 'abu ', 'alec ', 'alek ', 'aleksander ', 'alex ', 'alexander ', 'aaron ', 'adam ', 'andrew ', 'anthony ', 'archer ', 'arthur ', 'austin '];
last = ['williamson', 'davidson', 'edwards', 'ingram', 'olsen'];
name = "";
length = Math.floor(Math.random()) + 1;
for (i = 0; i < length; i++)
name += (first[Math.floor(Math.random()*first.length)]
+ last[Math.floor(Math.random()*last.length)]);
name = name.charAt(0) + name.slice(1);
document.write("<p id='name'>" + name + "</p>");
</script>
<p id="refresh">
<a href='#' onclick='window.location.reload()'>Generate a New One</a>
</p>
</body>
</html>