I’ll be the first to admit my Javascript is pretty lowly. Today I boosted it from “not really very existant” to “working and bodgeable”. My PHP is OK, my XHTML is very good, and my Javascript sucks. Anyhow, I was working on some basic arithmetic stuff and tearing my hair out.

So, I was trying to add some variables – variables I had already successfully multiplied – but they kept on concatenating. How irksome. So I investigated how to change the type of variables. Now, I appreciate the benefits of weak typing and all, but the first article I ran across said “the great thing about Javascript is that it’s not typed at all!“. Which didn’t help a lot. Eventually I found a way of doing it (that wasn’t subtracting the inverse); it was the delightful Number() function. Which doesn’t appear to be much of a function at all.

That was sentence number one. I didn’t think it could get worse, but oh, it did.

So I want to make sure we’re only dealing with integers in this web page. So I investigate how to convert any number to an integer (which will happen onKeyup or onKeydown). And the first (vaguely) helpful article I find says: “Javascript doesn’t have integers. It just has Numbers“. The article went on to explain that you should either round Numbers down or up to turn them into integers. At this point I could have cried.

Still, I got the application working in the end. I’m going to learn more (if only to take advantage of way more DOM scripting and Ajax), but I’m going to have to take it in small doses. Or else I won’t have much hair left.