View Single Post
Old 01-12-2013, 09:19 PM   PM User | #4
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,210
Thanks: 59
Thanked 3,996 Times in 3,965 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
And in any case, this line is *NOT* valid JavaScript:
Code:
Declare Numeric totCust	 // total Customers
JavaScript does not use a Declare statement to define variables. Also, you can't even tell JavaScript what the data type of a variable is when it is created (among other reasons, because the type can be changed at any time).

In JavaScript, you would just write
Code:
var totCust; // total Customers
I strongly suspect this is the idiotic book that tries to first teach you a PSEUDO-LANGUAGE (supposedly to make it easier to think about HOW to solve problems) and then has you convert the pseudo-language into JavaScript.

I feel sorry for you, that your stupid stupid instructor would choose this horrible book out of all those available.

And, yes, you can use Windows Script Host to execute pure JavaScript files, but then the way you ask the user to enter values and the way you display results are *COMPLETELY* different than you would use in a Web browser and so you will just have to un-learn all the WSH stuff when you start using JS in a web-based system. On top of that, debugging in the WSH environment is a pain in the neck. At a minimum, you need to download the Windows Script Debugger and you probably should instead use Visual Web Developer Express. A lot of overhead for a little debug help.

So you are better off just writing HTML code and then debugging it in a web browser.

All modern browsers except FireFox come with a debugger built in (and FireBug can be plugged into FireFox and used as its debugger). All of them can be invoked by simply hitting the F12 key.

MSIE 9 is not too bad for debugging, but I think that CHROME is a better choice. There are just a handful of differences, but that handful are enough to make using Chrome much easier, especially when just beginning.

And while you *CAN* create your JS code in a ".js" file and then attach it to a web page as Felgall shows (and as you will want to do when you get more advanced), especially when you are just starting this is more of a pain than it is worth. Instead, just embed your JS code right into your HTML code. Just use
Code:
<html>
<body>
<script type="text/javascript">
... put your js code here ...
</script>
</body>
</html>
Later, you will learn when to put the JS code into the <head>...</head> section of the HTML and when to leave it where I show it there. But given what we know about that atrocious book, the way I show it there is likely the best starting spot.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.

Last edited by Old Pedant; 01-12-2013 at 09:25 PM..
Old Pedant is offline   Reply With Quote