Welcome to the TechSpot OpenBoards. Please read the FAQ if you have any questions. Sign up or Login to participate.
Collaborate in the cloud with Office, Exchange, SharePoint, and Lync
|
|||||||
Collaborate in the cloud with Office, Exchange, SharePoint, and Lync
Javascript trouble
![]() |
|
|
Thread Tools | Search this Thread |
|
#1
|
|||
|
|||
|
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>
Last edited by Spike; 05-06-2004 at 02:19 PM.. |
|
#2
|
||||
|
||||
|
Thou shalt not have quotation marks in Math.round function
|
|
#3
|
|||
|
|||
|
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. |
|
#4
|
||||
|
||||
|
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?")
}
|
|
#5
|
|||
|
|||
|
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>
Any pointers??? |
|
|
|
#6
|
||||
|
||||
|
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.
|
|
#7
|
|||
|
|||
|
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>
|
![]() |
| Similar Topics | ||||
| Topic | Replies | Forum | ||
Javascript problems
|
2 | Windows OS | ||
Javascript problems
|
6 | Software Apps | ||
JavaScript disabled
|
2 | Virus and Malware Removal | ||
Need Javascript help
|
2 | Software Apps | ||
IE 6 Javascript Errors
|
5 | Windows OS | ||
| Thread Tools | Search this Thread |
|
|
All times are GMT -4. The time now is 11:00 PM.



Javascript problems