I have the following code and when I click on a button, I want the alert to display the string in the prizes array that corresponds to the index equal to the button's number. I currently receive "Fresh Laundry!".
<button id="btn-0">Button 1!</button>
<button id="btn-1">Button 2!</button>
<button id="btn-2">Button 3!</button>
<script type="text/javascript">
var prizes = ['A Unicorn!', 'A Hug!', 'Fresh Laundry!'];
for (var btnNum = 0; btnNum < prizes.length - 1; btnNum++) {
document.getElementById('btn-' + btnNum).onclick = function() {
alert(prizes[btnNum]);
};
}
</script>