View Single Post
Old 01-12-2013, 10:18 PM   PM User | #7
Modify_inc
New Coder

 
Join Date: Jan 2013
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Modify_inc is an unknown quantity at this point
Quote:
Originally Posted by Old Pedant View Post
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.
Thanks for your input, and your opinion of the book. I believe you may be right about the book teaching a Pseudo-Language and then translating it later in the book. I have went through the code and added everything the WSH reported an error on and thought that I might finally get to see the JavaScript execute the code, but then WSH reported another subset of errors starting from the beginning again with "undefined" for Start and a simple Display command.

Is Start not required anymore, as the book states to use it? Does undefined mean the command is not recognized anymore?

To display and input text, the following commands are mentioned:

Display "Enter the # of customers for the first hour: "
Input count1

Also there is a Declare Constant NUM_HOURS = 4, I assume that since you stated Declare is invalid that I need to change this but wasn't sure how to go about it since it was a Constant, so I just swapped it for var which I'm sure is perfectly find in a test script of this nature.

I installed Firebug and it stated that it found no JavaScript in my html.

Mike
Modify_inc is offline   Reply With Quote