SitePoint Sponsor |
|
User Tag List
Results 1 to 5 of 5
Thread: Simple JS - Need some help
-
Jun 1, 2005, 20:49 #1
- Join Date
- Jun 2004
- Location
- SitePoint.com
- Posts
- 121
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Simple JS - Need some help
Does anyone see anything wrong with this? It doesnt seem to work...
Code:function addition(a,b) { var result = a + b; return result; } var final = addition(3,4); document.write(final);
~("~) - Aloha!
-
Jun 1, 2005, 20:54 #2
very cryptic
what are you trying to do?
you can't have
var x = function
try
Code:function addition(a,b) { return a+b } var final; final = addition(3,4); document.write(final);
Last edited by hgilbert; Jun 2, 2005 at 03:55.
-
Jun 2, 2005, 03:50 #3
AhhhhHhhh !!
OK
the word final is reserved!
try another variable.
usually the simplest of things are the hardest to debug.
please ignore all previous comments
but try something else as the variable but not final.
always use Hungarian notation
so to keep to the same code as yours:
Code:function addition(nX,nY) { var nResult = nX + nY; return nResult; } var nFinal = addition(3,4); document.write(nFinal);
but you can see how the prefix can be used to avoid reserved name conflict.
the above code works (ive tested this time)
-
Jun 2, 2005, 11:37 #4
- Join Date
- Jun 2004
- Location
- SitePoint.com
- Posts
- 121
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Thanks!
~("~) - Aloha!
-
Jun 3, 2005, 08:41 #5
That's right there are some reserved words, and final is one of them.
But Hungarian notation is not the best way to name your variables
Bookmarks