...

View Full Version : Adding functions



chaseinchrist
05-31-2006, 11:29 PM
I hope that I don't annoy some people by posting this here, it's pretty basic, but I am learning Javascript from a website, and I have just gotten finished reading about Javascript Functions, and this is a pretty cool website that gives you assignments to do, and this particular assignment tells me to write a function that will add two numbers together at any place on the page.
This is what I typed:


<html>
<head>
<script language="javascript"><!--
function myAdder(){
var total= 23+56
document.write(total) }
//--></script>
</head>
<body>
<SCRIPT language="JavaScript">
<!--
document.write(myAdder(23,56))
//-->
</SCRIPT>
</body>
</html>

when I go to look at the result, I get 79undefined. What is undefined? I have tried alot with this script, so know that I don't come here as soon as I fail at something......Can somebody please find it deep deep deep down in their big heart to help me with this? Thanks in advanced
-Chaseinchrist

Mr J
05-31-2006, 11:59 PM
The 79 is from the document.write in the head section.
The undefined is from the document.write in the body.

Try it like this


<html>
<head>

<script type="text/javascript">
<!--
function myAdder(a,b){
var total= a+b
return total
}
//-->
</script>

</head>
<body>

<script type="text/javascript">
<!--
document.write(myAdder(23,56))
//-->
</SCRIPT>
</body>
</html>

or this


<html>
<head>

<script type="text/javascript">
<!--
function myAdder(){
var total= 23+56
document.write(total)
}
//-->
</script>

</head>
<body>

<script type="text/javascript">
<!--
myAdder()
//-->
</SCRIPT>
</body>
</html>

marilynn.fowler
06-01-2006, 12:15 AM
Mr. J:

Can you recommend a good free online javascript tutorial for those of us whose brain freezes up when we see the words "var" and "node?"

chaseinchrist
06-01-2006, 12:35 AM
Mr. J:

Can you recommend a good free online javascript tutorial for those of us whose brain freezes up when we see the words "var" and "node?"

I am using this (http://www.javascriptmall.com/learn/index.htm) website, if you are interested in that. I really like it because he types each lesson in a personal tone, so it's not just directions. After each "Class" he gives you an assignment that you have to complete on your own time. I'm only on lesson 5, and there are 14 lessons in all, but you gotta be willing to spend your time reading through it, you can't just skim, or you'll be really confused at the end of the lesson(saying from experience).
And thank you very much Mr. J for the help!

marilynn.fowler
06-01-2006, 02:23 AM
thanks! I'm starting to use it now.
EDIT:
I like this one. My eyes haven't glazed over yet.

boxxer03
06-01-2006, 04:49 AM
This site also has some good tutorials: http://javascriptkit.com/javatutors/index.shtml



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum