如何创建一个按钮来显示 javascript 中数组的随机结果?

How do you create a button that will display a random result from an array in javascript?

我一直在尝试创建一个按钮,该按钮将从数组中随机取一个名称,并将其显示在 html 页面上。已经尝试了很长时间才能使它正常工作,但没有结果。给出了什么?

此外,如果您知道答案,我该如何创建另一个按钮来显示多个结果,而不是只显示一个?

<!doctype html>
<html>
<head>
<script>
function postmessage(){
 return "Your new recruit is " + firstnames;

  var firstnames = ["John", "Jacob", "Eric", "Conroy", "Vincent", "Laurence", "Jack", "Harry",    "Richard", "Michael", "Kevin", "Daniel", "Cody", "Brody", "Chase", "Cash", "Norman", "Trevor", "Todd", "Ellis", "Quentin", "Zachary", "Bruce", "Sam", "Horace", "George", "Tom", "Tim", "Wallace", "Walter", "Alex", "Alan", "Sean", "Seamus", "Dudley", "Duke", "Damian", "Nash", "Horton", "Robert", "Mitchell", ];
  var firstnames = firstnames[Math.floor(Math.random() * firstnames.length)];
  var postmessage = "Your new recruit is " + firstnames;
 };
</script>

<meta charset="UTF-8">
<title>Untitled Document</title>
</head>

<body>
<input type="button" value="Get Recruit" onClick="postmessage();"/>
</body>
</html>

function postmessage() {
  var firstnames = ["John", "Jacob", "Eric", "Conroy", "Vincent", "Laurence", "Jack", "Harry", "Richard", "Michael", "Kevin", "Daniel", "Cody", "Brody", "Chase", "Cash", "Norman", "Trevor", "Todd", "Ellis", "Quentin", "Zachary", "Bruce", "Sam", "Horace", "George", "Tom", "Tim", "Wallace", "Walter", "Alex", "Alan", "Sean", "Seamus", "Dudley", "Duke", "Damian", "Nash", "Horton", "Robert", "Mitchell", ];
  var firstname = firstnames[Math.floor(Math.random() * firstnames.length)];
  document.getElementById("recruit").textContent = "Your new recruit is " + firstname;
};
<input type="button" value="Get Recruit" onclick="postmessage();" />
<div id="recruit"></div>