View Single Post
Old 03-04-2003, 01:55 PM   #1 (permalink)
saline
I am red.
 
saline's Avatar
 
Join Date: Feb 2003
Location: Cleveland, OH
Posts: 139
saline is on a distinguished road
Javascriptin' like there ain't no tomorrow

This week everyone gets to be artsy and creative.

I've made a web page (http://www.talonstar.com/brain_teaser_base.html) with a little JavaScript written into it. Now, I mentioned this before but, I love JavaScript. Lots of people think I'm an idiot for this but allow me to explain. They say JavaScript is horrible because it's so limited in what it can do. I say, you're just being lazy. I love JavaScript just because sometimes you really have to think how to accomplish problems in a new way because the way you wanted to do just isn't going to work. When I explain this people usually think I'm an even bigger idiot but I don't care.

I love JavaScript. You should too, don't be afraid of JavaScript. It's probably a lot more familiar than you think, it's a C based language so if you know C, C++ or Java (another C based language) you'll probably do alright.

Well, kind of. The web page and applet I've created does almost nothing but I've used and modified it before to do a bunch of different stuff. I made a very simple paint program, John Conways "Game of Life", I started doing a version of Sim City but after months and months scrapped it for some later day. I love it because it's so simple, see I'm a minimalist at heart, crazy flashy graphics, sounds, colors who needs it? Give me a way to represent on and off and I'll find some way to amuse myself, it's just how I am.

"SO WHAT'S THE PROJECT ALREADY!!?"

Right I hear you, ok like I said this web page and applet does almost nothing, all it does is change the section you click on from white to black and back again. Well that's the project. Expand it. Make it do something. I'll make some recommendations depending on your abilities.

If you know what your doing (especially if you're familiar with JavaScript) why not try to make a game? Pong, znake, falldown most simple games are possible with a little creativity. If you don't want to do a game try implementing some spiffy paint tools. Try expanding it so that the user can click and drag to draw, an undo option, a shape tool for circles and rectangles, flood fill can be somewhat difficult as well. One of the things that I've always thought about doing but never did was allowing users to save the images they make by writing a cookie with some sort of code to indicate the color and order of the squares.

Or come up with something that's completely not occurred to me here I'd love to see it!

Intermediate programmers might try to implement simpler tools than flood fill and shapes. Horizontal lines, Vertical lines, color replace. If you didn't want to try the paint program simple simulators like "The Game of Life" are a good challenge and I've always found them to be really cool and very rewarding. If you've taken AP comp sci in the last three years you'll recognize similarity to the fish breeding case study, if not, don't ask, it's a long story. I highly recommend "The Game of Life" it so check it out here:

http://www.math.com/students/wonders/life/life.html

If you're new to JavaScript or programming in general I would try a simple paint program. Allow users to choose and paint with more colors than just black and white, make a button or a link that, when clicked, will clear the entire drawing area to all white.

There are a few things that people who aren't familiar with JavaScript should know off the bat. First, there's nothing to download. If you're reading this it means you have a web browser which will work (except lynx, which doesn't count because I said so) and since I don't think there's an operating system out there that doesn't have a text editor you have everything you need. Still I would recommend downloading the following:

http://www.editplus.com

It's a great program which color codes HTML and JavaScript keywords and can be extended to code other languages. I use it all the time, I install it on every computer I work on and I owe them a bunch of money. Technically it's free to use for a trial period but the trial period never ends so it's kind of point less. I've been trying to save thirty dollars to send to them for like three years now and it just hasn't happened but it's on my list of things to do. Right above finishing college and below conquering the world. It's especially good for JavaScript because it has the only thing even approaching a debugger for JavaScript I've ever seen (I'm told IE has one but I've yet to find it).

Next thing you (mainly newbies) should know about JavaScript is that it's an interpreted language. I need to explain why this is significant. There are two kinds of programming languages interpreted languages and compiled ones. Interpreted languages (also known as scripting languages) like JavaScript, Perl, Python and many others work (more or less) as follows. When they're run an interpreter is needed to go through the code turn it into machine language and execute those commands every time the user wants to run the program. Depending on what the program is this can be somewhat inefficient as the computer needs to start the interpreter and go through each line of code every time the script (a script is a program written with a scripting language) is run. For JavaScript the interpreter is built into your web browser.

On the other hand a compiled language like C, C++, Visual Basic, Java and others creates a binary executable. What this means is the compiler essentially does what the interpreter does but once it turns everything into machine code it stops, saves that machine code as an executable of the same name as the file and adds little bits and pieces so that it will execute properly when a user tries to run it. This way the user directly accesses the machine code when they run the program so it can be a little faster but the files are larger. This is a very simplified version of what's happening in each case but I think it shows the difference.

Ok, so that said, JavaScript is an interpreted language, which means every time you run the script it has to get interpreted. This can be very slow. Because it can be slow it has been known to on occasion stall/crash computers. This means newbies specifically have to be careful when writing code, don't use giant numbers in loops. When setting the size of the grid that's drawn (the size variable), don't make the numbers too large. On my 1.3 Ghz I tried a 50x50 grid and it took nearly a full minute to load (partly because I need more ram but that's beside the point). So newbies, be careful, JavaScript can choke up kind of easily so try and keep things as efficient as possible. Generally JavaScript will load and run very quickly but it definitely has it's sticking points at times.

If you have questions about JavaScript I'll certainly try and help. I've got my trusty library at the ready for anything I can't field. In addition here are a few places that can help online

JavaScript at Webmonkey.com
http://hotwired.lycos.com/webmonkey/...ng/javascript/ - Thau's tutorial is one of if not the best on the web and I use it all the time.

Javascript.com
http://www.javascript.com

Netscape's reference, they know their JavaScript.
http://wp.netscape.com/eng/mozilla/3...ok/javascript/

This ended up being way longer than I intended it to be. So, off with you all, go be creative and make crazy old JavaScript lovin' uncle saline proud. You've nothing to fear but fear itself, and big loop numbers DON'T DO IT!!!

Jeez, these posts are getting longer and longer.
saline is offline   Reply With Quote