Welcome visitor
* Login
* Register
It is currently January 21st, 2019, 11:42 am
All times are UTC [ DST ]
* Search
View unanswered posts - View active topics

FORUMS » Client Side » JavaScript



Post new topic Reply to topic  [ 3 posts ] 
Author Message
  help to find the error
PostPosted: March 7th, 2009, 2:32 am 

Posts: 117
this is supposed to work as an exponential function but for some reason it is not working as it should, any idea what am i doing wrong?
<script type="text/javascript">
function exponential(){
var x=document.form.number.value;
exp= x*1;
var i=1;
for(i=1;i<=document.form.number.value-1; i++)
{n= n*n;}
window.alert("result is"+n);}
</script>


Top
 Profile  
 
  Re: help to find the error
PostPosted: March 7th, 2009, 2:40 am 
User avatar

Posts: 70
each time you run the loop 'n' changes so the second time its doing n^2*n^2, the third n^3*n^3 and so on. you may use another variable to store de results so 'n' doesnt change each time.


Top
 Profile  
 
  Re: help to find the error
PostPosted: March 7th, 2009, 2:45 am 

Posts: 117
:lol: you're right, sorry for the question :lol:


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

FORUMS » Client Side » JavaScript


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron