Making a traffic light test:
The first click switches the light to green. The second click doesn’t work. The code seems good. After the first click the redLight.png gets replaced by greenLight.png, and the browser displays a green traffic light. But on the second click, the browser should search, see “greenLight.png” and replace it with “yellowLight.png”.
Personally i would do this a different way, i would use CSS3 with jQuery and have an image fallback which is far more flexible and more maintainable in the long run. See the following jsFiddle for the demo.
Thanks, Chris for responding. Totally agree about your code sample being way more flexible. I’ve seen my programmer friends do really flexible working code with css and jquery.
I’m a noob at JS. This was more of a lesson/learning curve question for me on how the JS translator/processor works/thinks. I can match strings like the code below, but can I do that with images too? If so, why is my code breaking?
function helloTest(strTest){
var greetings = “Hello World!!!”;
var stringSent = document.forms[0].txtField.value;
if (greetings == stringSent){
alert(“it’s a match!”);
}