Hi I am trying to write code for an image to change every second depending on what is stored in an array. Heres what I have so far:
function parse_input(){
//initializes the input_text and the text_array variables
var input_text=document.getElementById('input_text').value;
var text_array=[];
//loops through input_text and if it is an alphanumeric character...pushes it to the text_array
for(var letter in input_text){
const LETTER_REGEX=/^[a-zA-Z0-9]+$/;
if(LETTER_REGEX.test(input_text[letter])){
text_array.push(input_text[letter]);
}
}
//function to change the image
function change_image(array){
document.getElementById('letter_image').src="images/"+array+".png";
document.getElementById('letter_image').alt=array;
}
//supposed to loop through the text_array and change the image every second.
for(var i=0;i<text_array.length;i++){
setTimeout(function(){change_image(text_array[i])},1000*i);
}
}
window.onload=function(){
document.getElementById('finger_spell_it').onclick=function(){
parse_input();
}
}
When I go to run the test I get an undefined variable. I don't know what I am doing wrong please help.