Jump to content

few javascript questions

Recommended Posts

I am far from new at javascript, I have been working with it for 4 years on and off, but I have never stepped out of the lines of doing form validation, and small stuff like that, now I want to start creating full java script programs in my spare time, and either selling them, or renting them out, or keeping them for fun. I understand all the basic and intermediate concepts of javascript, and actually tried writing a few programs but didn't out of lack of inspiration. I had a few question about some things I wasn't sure of as pertaining to javascript.1. Which is a better method Try Catch, or On Error.2. Should I start utilizing try catch on all my scripts, if so how do I utilize it with if, else, and other like constructs.3. What is the purpose of classes and what can they be used for, I have never used them, but I know the general format of setting them up and using, but don't see the point.4. I want to create some javascript programs, where do I turn for inspiration, any ideas on possible programs, you get credit for the inspirational idea.5. I have never had to use break so far, is it to get better timing during script execution. If so what do I need it for.6. I also had one more question, say for instance I created a time and date function, and wanted to link them to something that states times and dates are based on your browser settings do I do it like this or another way.All math functions all date functionsvar mydate = date functionsmytime = time functions you get the hint just showing youdocument.write('<a href="mydate.htm">mydate</a>');document.write('<a href="mytime.htm">mytime</a>');The mydate mytime.htm are the pages that tell that the browser settings is what controls the time and date, would this work for accomplishing this task7.I did a full math function doingtoday = new Date();document.write(today);and it brough up the full time and date, and everything, but most tutorials use all the getTime, getFullYear, and getDate, why don't they just do what I showed above, is there other way better for some reason.

Link to comment
Share on other sites

1. Try/Catch. Although I have hardly ever had a use for it.2. http://www.devguru.com/Technologies/ecmasc...ry...catch.html Just seems to me like it's avoiding the use of a function..3. such as class='something'? Classes are for styling the page, whereas the markup (HTML/XHTML) is supposed to be for the structure. So everywhere you're using style='this: xxx; that: xxx', or bold, italic, center tags etc, you should be doing that in your style sheet and referencing it through class= :)4. There are millions of things you can create in javascript, from floating fading windows to full blown RPG Hacks (with some server-side saving). It's up to you where you go :)5. Yes, say you're doing:

var iTD = document.getElementsByTagName('TD');for(i=0;i<iTD.length;i++){ if(iTD[i].innerHTML.match(/something/i) != null){    iTD[i].innerHTML = "this instead";    break; }}

The break stops after finding the TD, so you don't cycle through the rest of the elements unnecessarily.6. Not really sure what you mean.7. Sometimes you don't want the full date and time, or you need it in a different format. getTime brings up system time as far as i'm aware, more useful than the new Date() time if you're doing comparisons.

Link to comment
Share on other sites

1. Try...catch. More chances getting results2. Try...catch should be used right after function like this:

function myFunction(){try{if(){// code}else{}}catch(err){// handle error catching}}

3. I need to agree on this one, I also saw this javascript.internet.com - Snippets - getElementsByClass having a getElementByClass() function snippet if that's what you are asking.4. Yes I need to agree on this one too. You may take an object and explore it (for example the Math object and make an extracool calculator) or then do arrays or go on to ASP.5. I quess this has been also answered.6. I think that you need to add the <a> links into a page and add the time functions to the other page and the date functions to the other. Or you could do a clock and show them all in the same block of code :) 7. They also might want you to learn as much functions as you can. If you ever try to make a digital clock on your desktop (what I did but I failed), or something, you need these functions.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...