Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

If else question 1

Status
Not open for further replies.

ZekeO238

Programmer
Oct 1, 2002
32
0
0
US
Im bored in class, practicing my scripting and I have run into a problem. I made this script, basically, its a computer strobe light. I had it fully automatic at first then I added the prompt so the user could change the speed and now I want them to be able to type quit in the prompt to close the window. Here is the HTML
Code:
<html>
<head><title>Strobe</title>
<script language=&quot;javascript&quot;>
	<!--

	var speed=prompt(&quot;Choose a speed in milliseconds (10 - Real Fast | 100 - Fast | 1000 - Slow)\nPress F5 to change speed or type quit to exit.&quot;,&quot;50&quot;)
	bGrounds=new Array(&quot;black&quot;,&quot;white&quot;)
	thisBG=0
	bgColorCount=bGrounds.length

	if(speed=&quot;quit&quot;) {
		window.close
	}
	else{
		function strobeBG() {
			if(document.images) {
				thisBG++
				if(thisBG==bgColorCount) {
				thisBG=0
				}
				document.bgColor=bGrounds[thisBG]
				setTimeout(&quot;strobeBG()&quot;,3*+speed)
			}
		}
	}
</script>
<style>
body {overflow:hidden}
</style>
</head>
<body onLoad=&quot;strobeBG()&quot;>
</body>
</html>

I totally forget how to use If Else statements and I dont know if it is even close to being correct. If it takes too much work to add that would it be easier to add and onKeyPress to the body tag, like pressing 'Q' would close the window. Any help/suggestions would be appreciated.
Any help would be appreciated
 
Well, it's like this.... you're onLoad(strobeBG()) function will never be called because it's inside of an if/else statement. You'll need to make it a stand-alone function and call it from your if/else statement.

Also, it's good programming practice to end each statement with a semi-colon (;). There's always a better way...
 
Like I said, I have no clue about If Else statements so I jsut added and onKeyPress to the body. =)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top