/    Sign up×
Community /Pin to ProfileBookmark

Hi everyone, I am using the for loop function. I feel that my code is correct but something is wrong. I check for brackets and semicolon and they are in the right places and the right amount.

Can someone look at my code and let me know why it is not displaying/functioning. I am using the decrement operator with the for loop.
This code should make my code look like

1
2
etc

[code] function ForTest()
{
var OutPut=””;
FillArray()
for (var i=Numbers.length; i >= 0; i–)
{
OutPut = OutPut + Numbers[i] + “r”;
}
document.frmMain.txtaOutput.value = OutPut;
}[/code]

and I also tried it this way

[code]function ForTest()
{
var OutPut=””;
FillArray()
{
for (var i = Numbers.length – 1; i >= 0; i–);
{
OutPut = OutPut + Numbers[i] + “r”;
}
document.frmMain.txtaOutput.value = OutPut;
}
}[/code]

neither way is making my document work.

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@TheBearMayMay 30.2008 — Not knowing what FillArray() was doing for you, here's what I came up with using what you gave us:
[code=html]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type="text/javascript">
var Numbers= new Array();
function ForTest()
{
var OutPut="";
FillArray()
for (var i=Numbers.length-1; i >= 0; i--){
OutPut += Numbers[i] + "n";
}
document.frmMain.txtaOutput.value = OutPut;
}

function FillArray() {
for (i=0;i<10; i++) {
Numbers[i]=i;
}
}

if(window.attachEvent)
window.attachEvent("onload", ForTest);
else
window.addEventListener("load", ForTest, false);

</script>

</head>

<body>

<form name="frmMain">
<textarea name="txtaOutput"></textarea>

</form>

</body>
</html>[/code]

Since this works, my assumption is that the FillArray function is either malfunctioning or that the Numbers array isn't declared globally.
Copy linkTweet thisAlerts:
@jennifer_48219authorMay 30.2008 — oh my goodness, I feel so dumb. I found out what I was doing wrong. It was in my form. I did not let my form know that ForTest is a function. I do thank you for responding, it made me look at my form.
Copy linkTweet thisAlerts:
@TheBearMayMay 30.2008 — Main problem is your button for the For. Should read:
<i>
</i>&lt;input name="Button2" type="button" value="For" onClick="ForTest[B]()[/B]"&gt;
×

Success!

Help @jennifer_48219 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.5,
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: @Yussuf4331,
tipped: article
amount: 1000 SATS,

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

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...