- Review first quiz (web page of last question)
- Questions on assignment 3?
- Introduction to JavaScript
Here are some simple examples using JavaScript:
Here are some useful tips and references:
- JavaScript is case-sensitive. Generally, you will need to
type all commands in lower-case in order for your JavaScript to
work.
- Be careful where you start and close quotes for creating
literal strings.
- The online
tutorials often use
document.write for output. However, we won't
use that in this class since it's not useful for creating
interactive pages.
- Use JavaScript comments
to explain
what your JavaScript code does.
- Most input methods (e.g. prompts and text fields in forms)
produce a string. If you want a number, you may need to convert
the string to a number using parseFloat.
- Discuss Assignment 4
- Practice problem with JavaScript
- Discuss debugging strategies
- Types of errors
- Syntax error occurs when page loads, usually a typing error
- Run-time error occurs when a statement is executed
- Logic error causes incorrect output
- Delete (or "comment out") suspect code
- Using the alert function to trace code
- Help from Text Editor (e.g. Brackets)
- Color coding shows strings
- Matching parentheses are marked
- Check HTML code
- Help from browsers
- Google Chrome: Menu Icon (upper right, by the star) --> More Tools --> Developer Tools --> Console
- Firefox: Menu icon (upper right) --> Developer --> Web Console
- Internet Explorer: Tools --> Internet Options --> Advanced tab --> select Display a Notification about Every Script Error
What's wrong with this page?
Find the bugs in this tip calculator
page.
- Abstraction and Predefined Functions
Here's a simple page that uses a
predefined square-root function. Here's a reference to predefined
functions (look under JavaScript Math Objects and Javascript
Global Properties and Functions for the most common
functions).
Dave Reed has created a library of useful random functions. Here
is one example that uses the random
functions. Here's a link to these functions.
- Discuss Assignment 5