/    Sign up×
Community /Pin to ProfileBookmark

For loop issue!!!

For some reason when I open this script with any browser nothing is displayed. It should bring up something like the following:

1
4
27
256
etc.

Any help would be appreciated.

<script type=”text/javascript”>
var m, n;
n = 10;
m = Math.floor(Math.random() * n + 1); //generates a random number between 1
and 10. Then converts value to a whole a number.
for (i = 1; i <= m; i++)
{
document.write(Math.pow(m,i));
document.write(“<br>”);
}

</script>

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@KorMar 18.2006 — document.write() is not a dynamical method. Further more, is not a "concatenate" method. It will always write once and overwrite the result of the previous document.write(). U should use document.write only once.

Try

var txt=''

for (var i = 1; i <= m; i++)

{

txt += Math.pow(m,i)+'<br>';

}

document.write(txt);
Copy linkTweet thisAlerts:
@Digic25authorMar 18.2006 — Thanks for the quick response...

But I'm still getting the same problem of a blank page.


Tom
Copy linkTweet thisAlerts:
@KorMar 18.2006 — I don't think so:
[code=php]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta http-equiv="Content-Script-Type" content="text/javascript">
<script type="text/javascript">
var m, n;
n = 10;
m = Math.floor(Math.random() * n + 1);
var txt=''
for (var i = 1; i <= m; i++)
{
txt += Math.pow(m,i)+'<br>';
}
document.write(txt)
</script>
</head>
<body>

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


It works on any browser. Check whether your browser is javascript enabled or not
×

Success!

Help @Digic25 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.16,
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,
)...