View Full Version : learning javascript?
hairynugs6382
09-11-2002, 01:07 AM
Whats the deal with javascript i have been trying to learn it for over two years. And I just can't get it I even go looking at script seeing how they work. I have read and own over 10 javascript books. and after all that when i go to write a script they never work! Maybe two years isn't enough experience or maybe im just javascript impaired!
P.S. Should i just gove up and try to learn something like PHP?
chrismiceli
09-11-2002, 01:49 AM
programming ain't easy, do you know any other programming languages, I would not start with javascript. HTML is pretty simple, when you more complex like javascript if you know the basis of the language and the syntax stuff it should come to you. If you get errors, fix them then try again a week later or so. If you still can't do it don't give up, programming is so fun.
beetle
09-11-2002, 04:23 AM
HTML really isn't a programming language per se, but rather a Markup Language (the 'ML' in HTML ;))
If you've been studying Javascript for 2 years and have read 10 or so books, and still don't have the know how, then you need classroom instruction. And don't switch to PHP (it's harder, although the debugging and error-reporting is better, it's still a more complex language overall)
I've been coding Javascript for roughly 1.5 years and feel like I have a good grasp on it. However, I first learned programming 7 years ago when I was a junior in high school, and took two computer science classes (the language was Turbo Pascal). Now, although I've never used Turbo Pascal since then (and never will) those classes taught me about data types, pointers, array, sorts, if/then/else statments, loops, switch/case statements, functions and parameters, and many more of the basic programming concepts. All of which I use on a daily basis with javascript. In college I took a C/C++ class which helped me learn the C-style syntax, which javascript resembles in many ways. (Javascript is a C-based scripting langauge, PHP is too :D)
So, to wrap up, I think you need to concentrate on being the student, and let someone else be the teacher. Look around at local colleges for some entry level programming classes. Books are great, but they can't sit down next to you and tell you what is wrong with the script on your screen that doesn't work.
RadarBob
09-11-2002, 02:26 PM
I first learned programming 7 years ago when I was a junior in high school
There was no such a thing as personal computers when I was in Jr. Hi.!
Anyway, Beetle is pretty much on the mark...
Also, there is a big difference between knowing how to program and knowing the syntax of a particular language. Too often programmers get "one year of experience five times" rather than "five years of experience."
As a programmer and observer all these years I strongly suggest that you focus on learning the language and not try to apply your (currently) limited knowledge to actual stuff at this point. With applied effort were talking weeks or short months to get the basics. You'll save time in the long run; avoid being stuck with crappy, unmanageable code; and it'll be more fun when your stuff actually works! Your "..they never work" comment is a classic symptom of missing basics.
Anyway, work hard at understanding the basic syntax and *structures* of the language. You must understand what those curly brackets are about, for example, just so you can read basic code! Also you need a solid understanding of IF, WHILE, DO WHILE, SWITCH.. stuff like that.
Then you need to get familiar with the built-in "library functions." I've seen many times where a coder is writing convoluted code like mad when an existing, simple function will do the trick. In Javascript these functions are the string, array, math, etc. stuff. Most languages have many similar functions but may work slightly differently - also a language will have many functions unique to it.
Finally, and LASTLY you need to get into the "document object model" stuff - which makes Javascript what it is - a language for manipulating HTML web pages.
Every computer language has it's unique challenges and unfortunately to use Javascript you need to understand HTML too. And "server side" programming too. AND VBScipt - just because it's so ubiquitous in web development. This compounds your learning chanllenges and this is why I think Beetle suggests you find a different language to learn first.
Book Recommendations
Virtually every book out there tries to get you going as quickly as possible into the real task - writing real scripts for web pages (in the case of Javascript). They sacrifice a solid foundation of the basics to do this.
Whatever computer language you're learning if you ever find a book about it by "Deitel and Deitel" buy it - whatever the cost. IMHO they write EXCELLENT *textbooks*. They have How to Program titles for C, C++, Java, and several others, but not Javascript exclusively.
The Complete Internet & World Wide Web programming Training Course by Deitel & Deitel. Includes the book Internet & World Wide Web - How to Program. Our office just bought this last week and I fully expect this to be a superior text for learning over-all web programming. Yes, it teaches Javascript. No, you won't be truely expert when your done - but it's an organized, coherent beginning.
Pure Javascript is a most excellent reference. It's not a tutorial, it's a reference; and it's well done and thorough - unlike too many of these so called "The compelete reference" books.
Code Complete by Steve McConnell - if you're serious about learning how to program. The author uses C, BASIC, FORTRAN, languages for examples, but his advice applies across the board - which is his point of using multiple languages. I applied it extensively to a big COBOL program.
Whew! I'm tired.
Hope this helps! Good luck.:thumbsup:
beetle
09-11-2002, 03:13 PM
There was no such a thing as personal computers when I was in Jr. Hi.! Hehe. I can see how you misread that...I said when I was JUNIOR in HIGH SCHOOL, not 'when I was in Jr. High.' :D
BTW, my first programming experience EVER was in 1st grade when I did QBASIC on a TRS-80 :D
RadarBob
09-11-2002, 06:24 PM
OK, same answer... when I was Junior in High School, there was no such a thing as personal computers.
GateKeeper
09-11-2002, 06:59 PM
heheh, my first experience with the trash 80 was in HS. . .back when the good ol apple II was the big dog on the block and pascal and fortran were just coming out of the blocks. . . gods, I feel old now.
RadarBob
09-11-2002, 08:28 PM
Originally posted by GateKeeper
heheh, my first experience with the trash 80 was in HS. . .back when the good ol apple II was the big dog on the block and pascal and fortran were just coming out of the blocks. . . gods, I feel old now.
Call and raise...
The first "personal computer" I ever saw was a MITS ALTAIR, when I was a sophomore in college. It was delivered in kit form, had 1 (2?) kilobytes of memory and was programmed in machine language using a row of 9 toggle switches on the front panel (8 bits + a parity bit).
BTW the first time I saw a "trash 80" was in the Air National Guard Fighter Weapons School....
It was connected to a light board - like a draftman's table. One taped an aeronautical map to the table and clicked on the 4 corners of the map w/ a mouse-like cursor & then entered the map scale into the computer. Now the computer knew the map.
Then the user clicked all over the map creating a flight route defined by the coordinates of where the user clicked. Then by entering known winds and planned airspeeds, etc. a complete flight plan was spit out with time, distances, fuel used, etc. About 1 minute to do what took at least 30 minutes by hand - and never mind about changes!
And this was in 1981. So much for the TRS-80 bad reputation.
GateKeeper
09-11-2002, 08:59 PM
<just sort of bows down to the true old-timer>:D
whammy
09-11-2002, 09:00 PM
I used to program in BASIC on a "Trash 80" when I was a kid. :)
Roy Sinclair
09-11-2002, 10:50 PM
Originally posted by GateKeeper
<just sort of bows down to the true old-timer>:D
I started programming back in 1974 (HP1000E Timeshared Basic through 300 baud dialup while in High School) but there are a number of programmers I've know where I work and online that make me feel like a newcomer yet.
youngScripter
09-12-2002, 02:22 AM
I cant believe I heard you say that! Never give up! A good programmer knows that there is always somebody better than him, so that's what inspires him to keep going! If you get frustrated, then take a deep breath, look at the screen, and concentrate. If you still cant get it, then look for help around the net! Never give up! Never! :thumbsup:
hairynugs6382
09-13-2002, 12:10 AM
No I have no problem with other languages such as C++, C#,
if I can write that I should be able to write a simple javascript but it just does not agree with me! Perhaps I should take some scripting classes even though most of the other programming languages that I have learned I have self taught myself! And I was never really gonna give up just frusterated. I think that is is the mathimatical part that throughs me of Im not very good at math and especialy algebra so all the variable through me off maybe I should take some advanced algebra classes too? I'm still not going to give up on it it to much fun 4 me, but I am getting tired of using other peoples scripts! I'd like to write my own and I'd like to learn DHTML but that take some working knowledge of javascript. So you all think that I should try learning other lanuages before I jump into javascript any more than I have. anywaus my head is starting to hurt so I'll cut this off. Thanks for all the encouraging comments more are welcome any ideas or suggestions would be great! Thanks again everyone especialy beetle and radarbob thanks for the history leasson and the advice I will keep my eye out for any of those books even though I think I have enough( JavaScript Bible my asss!).
P.S. One more ? Is reading scripts off of other peoples sites a good way to learn Javascript. And is it true that one exact Script can be written 100's of different ways
If you know C++ and C# as you claim, then Javascript is just the loose (and friendly) equivalent of those.
There are a few fundamental differences, but for beginner's, you won't notice anything besides the loose-typed variables and functions
hairynugs6382
09-13-2002, 01:54 AM
I don't KNOW them like a proffesional but i can can write a program in C or C++ compile it and it works! With javascript its not like that!
beetle
09-13-2002, 04:22 AM
Well, the primary difference between any scripting/programming language and something like Javascrtript is this: DOM.
ASP, Java, PHP, Perl, C, C#, Pascal, Fortran, COBOL, etc etc have nothing to do with the Document Object Model. Sure, PHP and C and Javascript share lots of the same syntax, but only javascript (and vbscript) interact with the HTML document directly. This interface is the DOM.
If you are proficient enough to write simple programs in C, then I suspect that your trouble is not with the scripting aspect of Javascript, but rather with it's integration into an HTML page. Hang out and read some of the posts in the DOM scripting forum here at this site. You may just pick up a few things.
Also, you may want to pay attention to WHAT goes wrong with your scripts, (I'm assuming that you eventually fix them) If you are like I was, you will notice that there are several specific areas in which you commonly make mistakes (I used to try to perform math operations on strings all the time :rolleyes: )
Speaking of math, you mentioned you may have a problem there. Oftentimes the solution in programming certainly involves a complex/semi-complex math algorithm, so some study in that area may be to your benefit.
Best of luck
I commonly use pseudocode to help plan out scripts. This process helps me to think about the objects I might need and how I can use them.
Try to modularise your scripts. Break large scripts into smaller components or functions. It's easier to debug. Use alerts at crucial points in the script to see what values are being returned.
Try to write generic functions that you can reuse across pages.
Also, start a javascript library that contains all your successfull scripts. Keep it as a reference. When you need a script, lift from your library and use it (although you probably do this already).
GateKeeper
09-13-2002, 01:12 PM
I can fully understand your dilema here as I am in much of the same boat. I had always been interested in Javascripting for my pages and when I started working on the site I am currently building, I found a desire to have some nice little scripts on it to make it unique. Unfortunately I had no clue as to how to go about any of it until I happened across a UK site that delves into DHTML (paul.stephens web developement pages) (http://web.ukonline.co.uk/paul.stephens/pcp/pcpidx.htm)
When I saw what he did with filters, images and lights, I said to myself that I wanted to do that. Fortunately for me, I found this forum and the Javascript Kit Site (http://www.javascriptkit.com), both of which have helped me tremendously.
In the long run, my suggestion would be to just keep plugging away at it. I also strongly agree with both umm and beetle. I come to this forum at least once a day if not several times, just to see what is going on. I also look at other peoples scripts and try to figure out how they work and how they flow from function to function. I would strongly recommend the tutorials at JavasciptKit as well, I have learned loads from them, enough so that I am now beginning to write my own scripts instead of using other people's scripts.
Hang Tough:thumbsup:
GK
Guardian23
09-13-2002, 04:51 PM
About the 100 ways to do it thing,
it probably is true, considering that the perl motto is that there's
more than one way to do it.
But about the math, I'm a little confused, because so far, which
is only about a year and a half, I haven't come across anything
that required a math level above a common knowledge of variables
and how to count... So what is this big mystery about the relationship
of math and programming languages such as JScript and Perl?
Is it something to do with the "for" statement? Or does it have
some deeper meaning?
*highly confused*
Guardian
PS
ASP, Java, PHP, Perl, C, C#, Pascal, Fortran, COBOL, etc etc have nothing to do with the Document Object Model
Actually, you missed the part about Perl, it has a nice little dish on
the side called PerlScript, which has access to all the built in functions
and the DOM, unfortunately, you can't modify window variables,
while tag attributes can use the setAttribute method.
So it's usefulness is limited to it's ability to integrate with JS and VBS... :(
beetle
09-13-2002, 06:49 PM
Well, sometimes the math can be slightly complex. Like take this example. Imagine you had a form with a some sort of input (assume number data) and you didn't want the number string to all be the same number (id. 444 or 333333 or 8888888)
What's the best/quickest algorithm for solving this?
I can think of two methods. One with mathematics (2 lines), one with regular expressions (1 line).
Assume this setupfunction checkIt(str) {
alert(/* code here */);
}
<form>
<input type="text" name="numbers" />
<input type="button" value="Check It" onClick="checkIt(this.form.numbers.value);" />
</form>The alert should be 'true' if all the numbers entered are the same. The alert should be 'false' if all the numbers are not the same.
Anyone see these?
brothercake
09-13-2002, 07:02 PM
What isn't like that? Why not post a simple example of a script you can't get to work and we'll see if we can debug it for you. You might find that its just a conceptual leap that preventing it from all slotting into place for you :thumbsup:
TO echo what others have said - I started with JS about 2 years ago; it was the first lanugage I learnt and now I feel pretty much like there isn't much that JS can do that I don;t know how do to. Having said that, I still see things everyday that make me feel like I know nothing :rolleyes:
beetle
09-13-2002, 07:20 PM
Originally posted by brothercake
Having said that, I still see things everyday that make me feel like I know nothing :rolleyes: Isn't that the truth. I just learned about the existence of the push() method for arrays in JS and the identical operator (===)
allida77
09-13-2002, 07:29 PM
I pretty much learned from others "real world" examples and using the js reference at www.devguru.com. I am not a js guru but if I need a script or to debug I can figure it out.. If you know c++ you should not have that much of a problem. At least you know you are a beginner at it. Many programmers try to be experts before they can be beginners.
I am not that much of a math whiz but I get by....you should not have any problems....Functions are our firends!
By "real world" examples look at the most common uses of js: Forms, windows, and browsers. Do not waste with scripts that try to "kill an ant with a hammer".
My 2 cents
hairynugs6382
09-13-2002, 07:33 PM
Thats just it I don't know anything about the math part. I understantd simple things like joining to strings document.write('onething' + 'thenanother') but once it gets into a long repition of
numbers, variables, and operators I just have a brain fart! I think that taking some further math classing could help only problem is I have no time for that or even the capability of pasiing the class(I got Ds in all my high school math classes.). But i will take everything into consderation and try to take the classes if ample time. And I do and will check theses forums several times a day! THANKS for all the help and more suggestions and comments are welcome. And thanks for all the encouraging post especialy beetle, umm, gatekeeper!
beetle
09-13-2002, 08:06 PM
Here are the two versions of the checkIt() function that I asked about earlier.// Regular Expression method (better)
function checkIt(str) {
alert(/^(\d)\1*$/.test(str));
}
// Arithmetic method.
// Works, but generates rounding errors with number strings of 16 digits or more (would'nt work for credit cards :D)
function checkIt(str) {
for (var i=0, numStr=""; i<str.length; i++) numStr += "1";
alert((parseInt(str) % parseInt(numStr)) == 0);
}
Originally posted by hairynugs6382
And thanks for all the encouraging post especialy beetle, umm, gatekeeper!
Actually hairynugs6382, I'd like to thank you for helping me learn more about javascript. Attempting to provide good answers makes me consider the script (lol, even thought some answers are better than others) and this really helps me learn.
Mind you, I've got quite a few questions of my own to ask in the near future.
You know, I think you might be close to breaking through to a particular level of understanding about javascript, where a lot of stuff will 'gel'. Keep going!
:)
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.