I have 3 parallel arrays: fruit, colour, and shape
I would like each of the fruits to be a button. When the button is pressed the colour and shape of the fruit displays below. I have managed to display the buttons but when run only the last colour and shape are displayed as an alert when the buttons are pressed.
Here's my code:
var fruit = ["apples", "bananas", "oranges"];
var colour = ["red", "yellow", "orange"];
var shape = ["round", "long", "round"];
for(i = 0; i < fruit.length; i++) {
holder = colour[i] + shape[i];
document.getElementById("foo").innerHTML += "<button onclick='alert(" + 'holder' + ")'>" + fruit[i] + "</button>";
it does not seem to work when putting the colour and shape straight into the alert instead of the holder as shown:
document.getElementById("foo").innerHTML += "<button onclick='alert(" + 'colour[i] + shape[i]' + ")'>" + fruit[i] + "</button>";
//does not work
note: the arrays are much longer so it would not work to do each item separately. Also it would be better if the colours and shapes were displayed below instead of in a alert.
thanks in advance!