10/06/2005 P. Conrad, CISC103 Lecture Notes (0) Discussions (a) Need more clarity about submission of lab assigments concern that some completed labs are getting 0 or 1 not 2, because of misunderstandings Suggested solution: clear directory naming convention username, labnumber, checklist of which files are needed... (b) Question: what's on the midterm Today's answer: "everything above the line" line is the line on calendar below week of 10/09 and above the week of 10/16 Suggestion: material in the Ess Design series "sticks better" because you are doing something with it So better to emphasize that material on the exam... Some things from Chapter 7 of the Pink Book you should definitely know for the exam (these come from Self-Review Exercise 7.5 and 7.6... the complete solution is in the book, and also online as Ex07.06.product.html (1) How to declare variables in JavaScript e.g. var x; // declare one variable var x, y, z, result; // declare a list of several variables (1a) Know that every statement should end in a semicolon (2) How to prompt for a value var xVal; xVal = window.prompt("Enter first integer:",0); // note that this gets the value of xVal AS A STRING // note that "prompt" is a "method" of the "window object". (3) How to convert a string value to a numeric value x = parseInt(xVal); // Note that we call parseInt a "function" rather than // a "method" because it is not invoked using the "dot notation" // in the same way that document.writeln() or window.prompt() are. // Rule: all methods are functions, but not all functions are methods. (4) How to do math with an assignment statement: var result; result = x * y * z; (5) How to print out a result into the document: document.writeln("

The product is " + result + "

"); Take a look at 07.06.Addition.html to review these concepts... Now look at HowMuchLonger.html There are three problems that need to be fixed in that file. ********** If more time, continue with Chapter 08 problems... In chapter 8, the concept of pre-increment vs. post-increment is covered. We mention it, because you will sometimes see this in scripts written by others, and it is important to know the difference in case you do. However, the best idea is to not use either the pre-increment or post-increment in any context where the outcome depends on which one is being used. Only use i++; or i--; by itself to increment or decrement a variable. It is ok to use in a for loop: for (i=0; i<10; i++) document.writeln("" + i + ""); Or when counting something: count = 0; name = window.prompt("Enter a name (enter \"quit\" to quit):","Sheila"); while (name != "quit") { window.alert("Hi " + name); count ++; name = window.prompt("Enter a name (enter \"quit\" to quit):","Sheila"); } window.alert("I greeted " + count + " people today!"); But never have a postincrement or postdecrement appear on the right hand side of an assignment statement: x = i++; // bad y = --i; // bad or in a document.writeln() call: document.writeln(i++); // bad To do so is just a bad practice, since the outcome depends on whether the ++ is before or after the variable, and many folks find that confusing.