I've got problems with my variables when i'm doing a function. This is just a silly example. In my code I've got a lot of variables I want to use in the function so I don't have to write function over and over again for each variable "ex1, ex2 etc.." Below here is what I want to do really simple. First check for "ex1" where it equals the declared value, then perform action (animation in real code). Then do the same for "ex2" and so on. Is there a simple way to do this?
<script>
var ex1 = 'frog'; //Those are not set manually. ID's in real code
var ex2 = 'pig';
var ex3 = 'horse';
var ex4 = 'bird';
var x = 0;
setInterval("call", 5000);
function call(){
x++;
if(('ex' + x) == 'frog'){
//action a
}
else if(('ex' + x) == 'pig'){
//action b
}
else if(('ex' + x) == 'horse'){
//action c
}
else if(('ex' + x) == 'bird'){
//action d
}
}
</script>
window['ex'+x]. There should be a duplicate.windowholds all global variables.