Hi Student,
You've stumbled upon one of the many qwerks of JavaScript. This trips all of us JavaScript developers up. Let's look closer at the bug.
#####What's happening
If you put a console.log()
to reveal the value of the btnNum
variable when you click each button, you'll discover it's 3 despite what button you choose. So why is this?
You're right on track with your thinking here. I see you were expecting for the loop counter btnNum
to correspond to each respective value (index) in your prizes
array.
There are two things that causing this bug: