Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Go Back   Code Forums > Site Goodies > Saline's Brain Teasers
User Name
Password

Reply
 
LinkBack Thread Tools Display Modes
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
Old 03-05-2003, 07:48 AM   #2 (permalink)
MrMark
Registered User
 
Join Date: Feb 2003
Location: Washington, DC, USA
Posts: 2
MrMark is on a distinguished road
Re: Javascriptin' like there ain't no tomorrow

Javascript! :rock:

I too am a fan. I'd like to experiment with that sample site... but I have to move this weekend... I hate moving!

Quote:
Originally posted by saline
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).
I don't know if this is what's being referred to, but you can get error messages by clicking Tools - Internet Options, going to the Advanced tab, and checking off "Display a notification about every script error."

When you load a page with a script error, you'll get a typically vague Microsoft error box that says something like "There may be problems with this web page..." - if you click on Show Details, you'll see the actual error. It's not great, but it will at least tell you about missed closing parentheses and stuff like that. Even when the error messages themselves are completely useless, they do give you the line and character number where the error was found.

You probably want to disable this option for everyday browsing, though, because otherwise you'll get errors on almost every page!
__________________
MrMark is offline   Reply With Quote
Old 03-05-2003, 01:01 PM   #3 (permalink)
abc123
bloomberg
 
abc123's Avatar
 
Join Date: Jun 2002
Location: bloomberg
Posts: 263
abc123 is on a distinguished road
Send a message via AIM to abc123 Send a message via Yahoo to abc123
Re: Javascriptin' like there ain't no tomorrow

Quote:
Originally posted by saline

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.
what do you mean "c based"? the compiler and jvm for java are written in c but it is hardly "c" based, its oo and c is procedural, same with javascript javascript is oo, not procedural, i would not go comparing it to c...

also, you did not make an "applet" and applet is a specific java program not some block of javascript code...

but the game of life looks interesting in anycase.
__________________
-- bloomberg.
abc123 is offline   Reply With Quote
Old 03-05-2003, 02:41 PM   #4 (permalink)
saline
I am red.
 
saline's Avatar
 
Join Date: Feb 2003
Location: Cleveland, OH
Posts: 139
saline is on a distinguished road
interesting but minor points

Perhaps "similar" is a better word. The syntax is based on that of C. However since Javascript was written after C and had such incredible similarities it's fair to say it's design was influenced ie based on C. Additionally, the word applet wasen't invented for Java programs. It's really just another word for a program, I suppose script is a better term but really it doesn't matter either way.

The game of life does rock, it's super cool.
__________________
saline is offline   Reply With Quote
Old 03-05-2003, 03:17 PM   #5 (permalink)
abc123
bloomberg
 
abc123's Avatar
 
Join Date: Jun 2002
Location: bloomberg
Posts: 263
abc123 is on a distinguished road
Send a message via AIM to abc123 Send a message via Yahoo to abc123
no its not based on c at all, all programming syntaxes are similiar.

to say it is based on c is confusing at best, it is oo! it barely has differing variable types, not to mention it has exception handling - which c does not have at all, try/catch so its completely wrong to suggest its based on c.

the syntax is only similiar in the most basic forms anyway.
__________________
-- bloomberg.
abc123 is offline   Reply With Quote
Old 03-05-2003, 03:48 PM   #6 (permalink)
joe_bruin
LOAD "*",8,1
 
Join Date: Feb 2003
Location: la.ca.us
Posts: 254
joe_bruin is on a distinguished road
Quote:
Originally posted by abc123
not to mention it has exception handling - which c does not have at all, try/catch so its completely wrong to suggest its based on c.
hmmm....

Code:
$ cat main.cpp #include <iostream.h> int main(int argc, char *argv[]) { try { cout << "dude, i know" << endl; } catch(int e) { } return 0; } $ g++ main.cpp $ ./a.out dude, i know $
...looks like exception handling to me (not available in c, only c++).
__________________
joe_bruin is offline   Reply With Quote
Old 03-05-2003, 03:53 PM   #7 (permalink)
abc123
bloomberg
 
abc123's Avatar
 
Join Date: Jun 2002
Location: bloomberg
Posts: 263
abc123 is on a distinguished road
Send a message via AIM to abc123 Send a message via Yahoo to abc123
Quote:
Originally posted by joe_bruin
hmmm....

Code:
$ cat main.cpp #include <iostream.h> int main(int argc, char *argv[]) { try { cout << "dude, i know" << endl; } catch(int e) { } return 0; } $ g++ main.cpp $ ./a.out dude, i know $
...looks like exception handling to me (not available in c, only c++).
joe.. remind me again where i said c++ didn't have exception handling?
__________________
-- bloomberg.
abc123 is offline   Reply With Quote
Old 03-12-2003, 01:17 AM   #8 (permalink)
abc123
bloomberg
 
abc123's Avatar
 
Join Date: Jun 2002
Location: bloomberg
Posts: 263
abc123 is on a distinguished road
Send a message via AIM to abc123 Send a message via Yahoo to abc123
well i guess i'll take your lack of response as agreement
__________________
-- bloomberg.
abc123 is offline   Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -8. The time now is 08:01 AM.


Powered by vBulletin Version 3.6.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2006, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting
Open Circle