Welcome to the TechSpot OpenBoards. Please read the FAQ if you have any questions. Login to participate.

Go Back   TechSpot OpenBoards > TS Community > The Meeting 'spot'

Javascript trouble

Reply
Bookmark / Share this page
Thread Tools
  #1  
Old 05-06-2004
TechSpot Guru
 
Location: Bridgend
Member since: Nov 2003, 2,367 posts
Javascript trouble

I was just in a chat on WinMX, in which I was given the following script. He couldn't get it working, and I was also puzzled.

The trouble is, that now it's bugging me!

Can somewone tell me where this script is wrong?

Code:
<script language="JavaScript"> 

var counter

function looper()

{

counter = Math.round("Math.random()"*10)

alert("MICROSOFT SUCK! get out of this one billy!")

}

setTimeout("looper()",counter)

</script>
Now, I'm not the best at scripting. Not by a long shot, but I can't help but feel that theres not too much wrong with the above. I might be wrong though.

Last edited by Spike; 05-06-2004 at 02:19 PM.
Reply With Quote
  #2  
Old 05-06-2004
Mictlantecuhtli's Avatar
TS Special Forces
 
Location: Finland
Member since: Feb 2002, 4,749 posts
System specs
Thou shalt not have quotation marks in Math.round function
Reply With Quote
You can remove this banner by registering, join the TS Community for free.
  #3  
Old 05-06-2004
TechSpot Guru
 
Location: Bridgend
Member since: Nov 2003, 2,367 posts
Thanks.

The script still only gives me one alert and nothing else though. Given the alert message, I'm guessing it's supposed to do more. lol.

Would also help if my .js files weren't opening in dreamweaver. lol.
Reply With Quote
  #4  
Old 05-06-2004
Mictlantecuhtli's Avatar
TS Special Forces
 
Location: Finland
Member since: Feb 2002, 4,749 posts
System specs
You're supposed to get only one alert with that script. SetTimeout is a timer, not a loop function. If you want loops, use for or while functions. For example, an infinite loop could be
Code:
while (1<2)
{
   alert("How many times can you click this?")
}
Reply With Quote
  #5  
Old 05-06-2004
TechSpot Guru
 
Location: Bridgend
Member since: Nov 2003, 2,367 posts
Thanks. I have it now, although I don't know why!!!

Code:
<HTML>
<head>
<title>
test
</title> 

<script language="JavaScript"> 

var counter

function looper()

{

counter=Math.round(Math.random()*10)

alert("MICROSOFT SUCK! get out of this one billy!")

setTimeout("looper()",counter)

}


setTimeout("looper()",counter)

</script> 

</head>
This seems to be an infinite loop. Removing either or both of the setTimeout lines renders the script useless. I have no idea why this works, but it does on my machine.

Any pointers???
Reply With Quote
  #6  
Old 05-06-2004
Mictlantecuhtli's Avatar
TS Special Forces
 
Location: Finland
Member since: Feb 2002, 4,749 posts
System specs
Oh, my bad, setTimeout does indeed loop until the script is unloaded. Your last script is an infinite loop because once looper() is called, it calls itself with that setTimeout inside the function.
Reply With Quote
  #7  
Old 05-06-2004
TechSpot Guru
 
Location: Bridgend
Member since: Nov 2003, 2,367 posts
Thanks for clearing that up Mict.

The one thing that's still bugging me though, is why is it that I need BOTH setTimeout lines for the script to do anything at all?

Oh, BTW, The same guy just gave me this to look at. what a joker. lol

Code:
<html>

<head>
<script language="javascript">
while (1<2)
{
javascript:window.open('http://www.google.com')
}
</script>
<title>:)</title>
</head>

<body>

</body>

</html>
There's a couple of people I would be more than happy to trap with that. lol
Reply With Quote
You can remove this banner by registering, join the TS Community for free.
Reply
Thread Tools

Forum Jump

Similar Topics
Thread Thread Starter Forum Replies Last Post
Is ASUS in trouble? bnieco CPUs, Chipsets and Mobos 5 10-13-2004 12:15 AM
Javascript for a HTML <select> possible? RealBlackStuff Misc. Software & Utilities 3 09-14-2004 12:57 PM
trouble with MyDVD 4.5 ak_in_charge Audio and Video 0 06-30-2004 04:02 PM
Having trouble with S3 Graphics ProSavageDDR adamswife0324 Audio and Video 5 06-26-2004 11:20 PM
Multiple-display trouble with GeForce 5200 Omegavolt Audio and Video 1 03-06-2004 01:08 AM


All times are GMT -4. The time now is 02:47 PM.