JavaScript Tutorial

B

binnyva

Hello Everybody,

I am writing an interactive tutorial for JavaScript.
I created a text box into which the users can input
javascript commands. On pressing a button, these commands
will be evaluated.

It works fine - but won't show any error if the commands
are wrong. Is there a way to show an error if the 'eval'
command encounters an error?

You can check out this tutorial at
http://www.geocities.com/binnyva/code/javascript/basic_tutorial/index.html

This tutorial is to completely finished - so if you have any
suggetions/comments please let me know. If you think that I
have left out something important please send me a note
and I will see to the problem.
Thanks in Advance,
Binny V A
http://www.geocities.com/binnyva
 
M

Mick White

You can check out this tutorial at
http://www.geocities.com/binnyva/code/javascript/basic_tutorial/index.html

This tutorial is to completely finished - so if you have any
suggetions/comments please let me know. If you think that I
have left out something important please send me a note
and I will see to the problem.

You know that it works only in IE Windows?
You may want to learn how to reference a form control.

document.formName.elementName (dot notation)
Mick
 
R

Richard Cornford

Hello Everybody,

I am writing an interactive tutorial for JavaScript.
<snip>

<quote
cite="http://www.geocities.com/binnyva/code/javascript/basic_tutorial/va
riables.html">
JavaScript is a loose typing language. So you don't have to declare the
variables. But there is an option to do so. Use 'var' in front of the
variable you wish to declare - but you can leave that out if you don't
wish to work you fingers unnecessary.
</quote>

Tutorial or practical joke?

Richard.
 
R

rh

Hello Everybody,

I am writing an interactive tutorial for JavaScript.
I created a text box into which the users can input
javascript commands. On pressing a button, these commands
will be evaluated.

That's not exactly a new idea, but it has merit nonetheless.
It works fine - but won't show any error if the commands
are wrong. Is there a way to show an error if the 'eval'
command encounters an error?

If the user of your tutorial is running a modern browser, one that
supports the ECMA-262 Javascript standard, you can use the try-catch
constructs of the language to provide infomation about errors that may
occur during execution.

The problem is that not everyone runs up-to-date browsers, and
inclusion of try-catch will cause syntax errors when encountered in the
older browsers. The following example may provide a way to capture
errors in most browsers without causing syntax error grief in browsers
that don't support try-catch :

(/**/ prefixes the lines in order to maintain code formatting in this
posting)

<script type="text/javascript">
/*JRS*/
/**/ var checkTry = "try {}catch(e){}";
/**/ var testText = "This cannot be successfully executed!";

/**/ var EVAL;

/**/ var ahhFutz = function() { // try/catch is not available
/**/ EVAL = function (code) { eval(code) };
/**/ window.onerror = function(msg) { // Output message on error
/**/ alert( "Execution failed: "+msg);
/**/ }
/**/ // Wait for an event
/**/ }

/**/ window.onerror = ahhFutz;
/**/ eval (checkTry); // See if try/catch is available

/**/ EVAL = new Function("code", // try/catch is available, so use it
/**/ 'try { '
/**/ +' eval(code); '
/**/ +'} '
/**/ +'catch (e) {'
/**/ +' alert( "Execution failed for :"+code+'
/**/ +' "\\n\\n"+(e.message || e.description ) );'
/**/ +'}'
/**/ );
/*JRS*/

EVAL(testText);
You can check out this tutorial at
http://www.geocities.com/binnyva/code/javascript/basic_tutorial/index.html

This tutorial is to completely finished - so if you have any
suggetions/comments please let me know. If you think that I
have left out something important please send me a note
and I will see to the problem.

I like the humerous approach in the tutorial. However, as pointed out
in earlier posts, it appears that you have some learning and work to do
yet (as an example, note that the ++ and -- operators can be both
prefix and postfix, and may have considerably different effects
depending on their placement relative to the operand).

../rh
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,772
Messages
2,569,593
Members
45,111
Latest member
KetoBurn
Top