JavaScript Training


Current Time


Changing HTML Elements

There can be nothing written here, or something written here.


However, some browsers do not support Javascript.

Just hide the Javascript with the HTML comment tag to make sure it doesn't display as page content on those browsers.


JavaScript Functions and Events


Calling a function when a button is clicked.




JavaScript Statements




JavaScript Code: A sequence of JavaScript statements


JavaScript Blocks


JavaScript Variables aka Kill me now








Operators

= is used to assign values

+ is used to add values



Javascript Arithmetic Operators






The + Operator Used on Strings






Adding Strings and Numbers

The rule is:

If you add a number and a string, the result will be a string!



JavaScript Comparison and Logical Operators




JavaScript If...Else Statements


Conditional Statements

if statement - use this statement to execute some code only if a specified condition is true

if...else statement - use this statement to execute some code if the condition is true and another code if the condition is false

if...else if...else statement - use this statment to select one of many blocks of code to be executed

switch statement - use this statement to select one of many blocks of code to be executed



If Statement

This example demonstrates the If statement.

If the time on your browser is less than 10, you will get a "Good afternoon" greeting.



If...else Statement

This example demonstrates the If...Else statement.

If the time on your browser is less than 10, you will get a "Good afternoon" greeting. Otherwise you will get a "G'day sir" greeting.



If...else if...else Statement

This example demonstrates the if..else if...else statement.




JavaScript Switch Statement



The JavaScript Switch Statement

Use the switch statement to select one of many blocks of code to be executed.