I am attempting to create a bit of JavaScript that, on the click of a button, adds a tag filled with options. The options will be defined with an array called "roster". What I would like to see is a dropdown that has options for sanchez, ronaldo, and ozil.
var roster = [
"ozil",
"sanchez",
"ronaldo"
];
var reps = null;
var dropdown = null;
var scorerOption = "<option value='" + reps + "' class='scorerOption'>" + roster[reps] + "</option>";
function makeDropdown () {
dropdown = "<select class='scorer'>" + String(scorerOption).repeat(roster.length) + "</select>";
document.getElementById("rawr").innerHTML = dropdown;
}
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<p id="rawr"><button onclick="makeDropdown()">Select a player</button></p>
</body>
</html>
As you may notice, the and tags appear, but all have innerHTML's and values of "undefined". How can I change that so it displays the names sanchez, ronaldo, and ozil?