/    Sign up×
Community /Pin to ProfileBookmark

I have got the power maths thing:
document.write(Math.pow(2,1))
document.write(Math.pow(2,2))
document.write(Math.pow(2,3))
document.write(Math.pow(2,4))

I was wondering if there was any way to automaticaly carry on the sequence without writing out the full sequence.

to post a comment
JavaScript

13 Comments(s)

Copy linkTweet thisAlerts:
@KravvitzDec 17.2005 — Sounds like you want to use a for() loop. Use document.write() with caution.
var str='';
for(var i=1;i<=4;i++) {
str += ((i>1)?', ':'')+Math.pow(2,i);
}
document.write(str);
Copy linkTweet thisAlerts:
@tiffeyneohelpauthorDec 17.2005 — Thanks, I didn't thing of that.
Copy linkTweet thisAlerts:
@CharlesDec 17.2005 — <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Power to the People</title>
<ol>
<script type="text/javascript">
var n, i = 1
while (n = Math.pow (2, i++), n < Number.MAX_VALUE) {document.write ('<li>', n)}
</script>
</ol>
Copy linkTweet thisAlerts:
@tiffeyneohelpauthorDec 17.2005 — How would you do it so that it had a textbox, and you entered a number into it, and it calculated that number individually
Copy linkTweet thisAlerts:
@CharlesDec 17.2005 — <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Content-Script-Type" content="text/javascript">
<title>Power 2 the People</title>
<div><input onchange="this.value = Math.pow(2, this.value)" onfocus="this.value = ''" type="text"></div>
Copy linkTweet thisAlerts:
@tiffeyneohelpauthorDec 17.2005 — <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Content-Script-Type" content="text/javascript">
<title>Power 2 the People</title>
<div><input onchange="this.value = Math.pow(2, this.value)" onfocus="this.value = ''" type="text"></div>
[/QUOTE]

Thanks. I'm not very good at JavaScript
Copy linkTweet thisAlerts:
@tiffeyneohelpauthorDec 17.2005 — How would you do it so it took away 1 from the entered number, and them did the sum?

so the equation would be: 2^x-1

Or divised the answer by 2.
Copy linkTweet thisAlerts:
@tiffeyneohelpauthorDec 17.2005 — Don't worry, i've got it
Copy linkTweet thisAlerts:
@tiffeyneohelpauthorDec 17.2005 — How would you do it, so that it displays NaN, if the number is 0 or below?
Copy linkTweet thisAlerts:
@tiffeyneohelpauthorDec 17.2005 — hello[/QUOTE][/QUOTE][/QUOTE][/QUOTE]
Copy linkTweet thisAlerts:
@CharlesDec 17.2005 — <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Content-Script-Type" content="text/javascript">
<title>Power 2 the People</title>
<div><input onchange="this.value = this.value > 0 ? Math.pow(2, this.value) : 0" onfocus="this.value = ''" type="text"></div>
Copy linkTweet thisAlerts:
@tiffeyneohelpauthorDec 30.2005 — After about 55, it rounds it up to the nearest 10. How would you prevent it from doing that?
Copy linkTweet thisAlerts:
@Orc_ScorcherDec 30.2005 — Use another programming language or write your own math routines.
×

Success!

Help @tiffeyneohelp 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.18,
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,
)...