JavaScript timer error

hi,

I have been playing around with JavaScript a i can’t seem to get the code below to work properly.
If I give backgroundColor(letter) a number between 0-9 it works fine but if I give it a-z it does not
work. All get in the in the console unexpected token, the alert shows the right letter I have pressed

any ideas?


function backgroundColor(letter){
	alert(letter);
	  document.getElementById(letter).style.color = "orange"; 
	  
	  window.setTimeout("backgroundReturn("+letter+")", 250);
	  
}
/*returns the keybroad to white after keypress*/
function backgroundReturn(letter){
	
	 document.getElementById(letter).style.color = "white";
	
}



II would have expected the results to be the other way around since it isn’t valid to start an id with a number.

You could try fixing up the setTimeout to pass a function as is expected rather than a string and see if that helps.

setTimeout(function() {backgroundReturn(letter);}, 250);