I'm trying to use HTML and JavaScript to create a simple program that will draw a random card from a deck that the user selects. The issue I'm running into is finding a way to use the option value from the HTML tag as a variable in the JavaScript function that draws the card. Here is my broken code.
<select id="hearts">
<option value="hd12">-12</option>
<option value="hd11">-11</option>
<option value="hd0">-10</option>
<input type="button" onclick=drawFunction() value="Draw A Card">
<p id="draw"></p>
<script>;
var hd12 = ["AH"];
var hd11 = ["KH", "AH"];
var hd10 = ["QH", "KH", "AH"];
function drawFunction() {
var deck = document.getElementById("hearts")
var rand = deck[Math.floor(Math.random()*deck.length)];
document.getElementById("draw").innerHTML = rand;
}
;
I know if I replace "deck" with the name of the array variable the draw will work. So I'm just missing how to define "deck" using the selected option.
This is my first coding project so I'm sure I'm missing something simple. Thanks for your time and help.