Go Back   CodingForums.com > :: Client side development > JavaScript programming > JavaScript frameworks

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-22-2011, 03:53 AM   PM User | #1
verynoob
New to the CF scene

 
Join Date: Nov 2011
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
verynoob is an unknown quantity at this point
help! function not defined error

I know you guys can catch my error here. I'm very, very new to JavaScript and don't have the ability to catch simple syntax errors, which I think might be my problem here. I also get a "missing } after function body" error on line 1, which I don't think I actually have.

Code:
<!doctype html>
<html>
 <head>
   <title>Sum of Numbers Below N that are Multiples of 3 or 5</title>
	<script type="text/javascript">
   function sumOfMultiples(){
   //runs the sum of all natural multiples of 3 and 5 below 1000
   var i = 1, ans = '', sum = 0;

	//generate natural numbers 1 .. 999
	while(i < 1000){
   		//test: multiple of 3 or 5?
	    if((i % 3 == 0) || (i % 5 == 0)){
      	sum += i;
      	ans = ans + i + ' ';
   }
   ++i;
}
//display result
alert(sum);

 </script>
 </head>

 <body>
   <p>
     Contents of the page.
   </p>
   <input type="button" value="Sum of Mults" onclick="sumOfMulitples();">
   <hr>
   <div id="outputDiv">
     Welcome to my site!
   </div>
 </body>
</html>
verynoob is offline   Reply With Quote
Old 11-22-2011, 08:26 AM   PM User | #2
devnull69
Senior Coder

 
Join Date: Dec 2010
Posts: 2,261
Thanks: 10
Thanked 533 Times in 527 Posts
devnull69 will become famous soon enough
sumOfMulitples is not the same as sumOfMultiples (mind the order of the letters)

And if you count the number of { and the number of } you'll see that you have 3 times { and only 2 times } ... that's a mismatch
devnull69 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:03 PM.


Advertisement
Log in to turn off these ads.