Hi everyone -
I'm currently learning JavaScript at a university level (so still pretty basic level teachings) but I'm stumped on how to perform this request.
Basically I have two images (one is a tiny blue ball and one is a tiny red ball) and a button "Change Color". They start out one Red and one Blue.
I have to design it so it's changing the color of the balls. Starting with the color combination of two balls(blue,blue), any button click must lead to the following color combinations repeated cyclically: (blue,red), (red,blue), (red,red), then again (blue,blue)...
Both balls have their own image file as well. I have the basic structure down to just switch between Red and blue over and over but I'm stumped at this point...any suggestions?
Code
<script type="text/javascript">
function lampSwitch() {
var temp = document.images["left"].src;
document.images["left"].src =
document.images["right"].src;
document.images["right"].src = temp;
}
</script>
<img src="ballred.gif" name="left" />
<img src="ballblue.gif" name="right" />
<p>
<form>
<input type="button" value="Switch"
onclick="lampSwitch()" />
</form>
Thanks!