469,273 Members | 1,790 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,273 developers. It's quick & easy.

5003 error message in JavaScript

Hi. whenever I try to run this, I get the message,"Cannot asign to a function result." Can anybody help? By the way, it's supposed to ask for a number 10 times, and then add them upp and show the sum on the page. Thanks.

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <body>
  3.  
  4. <script type="text/javascript">
  5.  
  6. var num = new Array(10);
  7. var total;
  8.  
  9. for (ctr = 1; ctr <= 10; ctr++){
  10. num(ctr) = prompt("Please type in a number:", " ");
  11. total = + num(ctr);
  12. }
  13. document.write(total);
  14.  
  15. </script>
  16.  
  17. </body>
  18. </html>
May 26 '07 #1
2 1224
Logician
210 100+
Expand|Select|Wrap|Line Numbers
  1. num(ctr) = prompt("Please type in a number:", " ");
Arrays are subscripted with square brackets [] ,,,,yawn.
May 26 '07 #2
pbmods
5,821 Expert 4TB
Heya, jarjarboy. Welcome to TSDN!

This doesn't directly solve your problem (see Logician's post for that), but it will fix the next one:

Expand|Select|Wrap|Line Numbers
  1. total = + num(ctr);
  2.  
This s/b:

Expand|Select|Wrap|Line Numbers
  1. total += num[ctr];
  2.  
http://developer.mozilla.org/en/docs...ment_Operators
May 27 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

4 posts views Thread by Geoff Cox | last post: by
3 posts views Thread by Gary Varga | last post: by
1 post views Thread by Joe | last post: by
11 posts views Thread by TJM | last post: by
1 post views Thread by JumpingOffPlace | last post: by
8 posts views Thread by Taras_96 | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.