Read: 04a -Dynamic web pages with JavaScript
introduction for JS:
BEHAVIOR LAYER .js files This is where we can change how the page behaves, adding interactivity. We will aim to keep as much of our JavaScript as possible in separate files. Create a folder to put the example in called cOl, then start up your favorite code editor, and enter the text to the right. A JavaScript file is just a text file (like HTML and CSS files are) but it has a . j s file extension, so save this file with the name add-content . j s
- When you want to use JavaScript with a web page, you use the HTML **The HTML
-
A script is a series of instructions that a computer can follow one-by-one. Each individual instruction or step is known as a statement. Statements should end with a semicolon.
- JAVASCRIPT IS CASE SENSITIVE
- You should write comments to explain what your code does. They help make your code easier to read and understand. This can help you and others who read your code
- MULTI-LINE COMM ENTS
- SINGLE-LINE COMMENTS
A script will have to temporarily store the bits of information it needs to do its job. It can store this data in variables.
** JavaScript DATA TYPES distinguishes between numbers, strings, and true or false values known as Booleans.**
Here are six rules you must always follow when giving a variable a name:
- The name must begin with a letter, dollar sign ($),or an underscore (_). It must not start with a number.
- All variables are case sensitive, so score and Score would be different variable names, but it is bad practice to create two variables that have the same name using different cases.
- The name can contain letters, numbers, dollar sign ($), or an underscore (_). Note that you must not use a dash(-) or a period (.) in a variable name.
- Use a name that describes the kind of information that the variable stores. For example, fi rstName might be used to store a person’s first name, l astNarne for their last name, and age for their age.
- You cannot use keywords or reserved words. Keywords are special words that tell the interpreter to do something. For example, var is a keyword used to declare a variable. Reserved words are ones that may be used in a future version of JavaScript. ONLINE EXTRA View a full list of keywords and reserved words in JavaScript.
- If your variable name is made up of more than one word, use a capital letter for the first letter of every word after the first word. For example, f i rstName rather than fi rstnarne (this is referred to as camel case). You can also use an underscore between each word (you cannot use a dash).
example of JS code
