I have the following dropdown option in a form:
<select id="candidates">
<option value="select">Pick one</option>
<option value="Candidate 1">Candidate 1</option>
<option value="Candidate 2">Candidate 2</option>
<option value="Candidate 3">Candidate 3</option>
</select>
And I also have the following array defined:
const selectedcandidate = ["/image1.png", "/image2.png", "/image3.png"];
I’m trying to declare a variable that will contain the image file of the corresponding candidate that was selected from the dropdown:
finalselectedcandidate = selectedcandidate[candidates[n]];
However, the code above doesn’t work. What would be the best way to accomplish this?