I have a function that it includes an array of colours, and there is a button and a text tag. So after each click, the function take the current index of the array, show it in the text and add one to the index number so next time the next index will be shown.
Here is my code:
var mycolor = 0;
var color = function() {
var list = ["red", "blue", "green"];
return list[mycolor];
mycolor++;
};
function run(){
$(".demo").text(color());
}
Any idea? how to fix it? currently it only shows the first index, it does not update it the variable.
returnstatement