Introduction to JavaScript Introduction to JavaScript Section 1:Java Script Syntax Java Script is a programming language that consist of a series of statements. These statements are used to tell computer to complete specific task. All statement are separated by semicolon. Example 1.1 var a = 1; var b=8; Tip: Java Script will ignores multiple white space. var a = 1; and var b=8; will be regarded as same format, which means var b=8; can also be written as var b = 8;. var a = 1; and var b = 8; are statements. They are separated by ; , and each statement start from a new line. In example 1.1, it uses var . var is called the keyword. It means variables. The keyword var told computer to build a variable( will be discussed later in section 2). Section 2: Java variables and data types Sometimes you want to use a variable to store a value in JavaScript, so that you can use it later. Then you need to know how to use a variable. Example 2.1 var x = 3; var y = 6; var z = x + y ; Example 1.1 gives x a value 3 and gives y a values 6, then it assign z to be the sum of x and y.Therefor the value of z is 9. Example 2.2 var distance = 5670; var speed = 123; var time = distance/speed; Tip Notice that in example 1.2, the sign of division is represented as / , and multiplication is represented as *. The = means assign value 5670 to variable distance. You can not only give these variable a integer value, but also other information like characters and strings. Example 2.4 var firstName = "Andy"; var gender = "Male"; Tip: Java Script is case sensitive, Which means var first firstname and var firstName are two different variables. In example 2.3, variable name and gender holds a String variable (must be inside double quotation marks). And in example 2.1 and 2.2 are Number variables. Sting and numbers are both primitive type variable. There are 6 primitive type. The other 4 are: Boolean, Null, Undefined and Symbol. (We will only use number and string in our excises). if you want to know more about the other four type, click here! Exercise: Q 2.1 Create variables that used to store the information of yourself, like your name, age, gender, home address and your habits. Q 2.2 Create four variables that could calculate the difference and quotient between two numbers.(Hint: you could use operation"%" to calculate quotient.) Section 3: Using Java Script in HTML In HTML 5, Java Script are instructions to be executed by web browser. In order to display data using Java Script in HTML, you can use window.alert() and innerHTML. You can use window.alert() to display data via alert box. Example 3.1 <html> <body> <h1>My First Web Page <p>My first paragraph. <script> window.alert(5+6);