/    Sign up×
Community /Pin to ProfileBookmark

Strange loopbehavior:

Please don’t test this code at your PC, because that will lead into several PC crashes. Something is wrong with the loop…
The meaning of this code is that it writes some sentence (sentence=zin in dutch), letter by letter. After is has finised a sentence, it goes to the next sentence (next arraykey).
Testing the code gives a “unknown error” at the line of

[CODE]setTimeout(“talk()”,150); [/CODE]

[B]Coding: [/B]

[CODE]
<script language=”javascript”>
var zin = new Array();
zin[0] = “text 1”;
zin[1] = “Text 2”;
zin[2] = “Text 3”;

function talk()
{
var x = 0;
var nummer = 0;

while (nummer != zin.length)
{
var spreekzin = zin[nummer].substring(0,x);

document.getElementById(“praatballon”).value=spreekzin;

if (x == zin[nummer].length)
{
nummer++;
x= 0;
}
else
{
x++;
setTimeout(“talk()”,150);
}
}
}
</script>
<input type=”text” id=”praatballon” readonly=”readonly” style=”width: 300px; height:50px;” value=”” onclick=”talk()”>
[/CODE]

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@A1ien51Apr 06.2005 — I think you logic on how your looping is done is wrong.

not sure how it would break out of the while loop. Plus you are calling a timeOut which means it will fire this while loop countless times.

Eric
×

Success!

Help @Grubolsch spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.27,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...