Presentation is loading. Please wait.

Presentation is loading. Please wait.

TECH 2018 (Week 16) Topic: JavaScript Parminder Kang Home: Phones Off Please.

Similar presentations


Presentation on theme: "TECH 2018 (Week 16) Topic: JavaScript Parminder Kang Home: Phones Off Please."— Presentation transcript:

1 TECH 2018 (Week 16) Topic: JavaScript Parminder Kang Home: Phones Off Please

2 –Introduction –W3Schools –This week’s topics: Basics Variables Conditional Statements (If…..else)

3 1 What is JavaScript? JavaScript is Scripting language or programming tool; used to add o functionality and o interactivity to web pages. known as light weight programming; no need to compile script before execution. JavaScript is directly embedded to HTML page. Why JavaScript?

4 2. Using JavaScript: document.write(“this is JavaScript”); Start and end of script.

5 2 Understanding Script statement: JavaScript includes the concept of object, method and properties. e.g. objectName.methodName() document.write(“text”) similarly, objectName.property = “somevalue” document.bgColor = “Blue”

6 2.1 Where to place JavaScript: Using in head section ensures that JavaScript is executed before anyone uses the page. implementation: triggering an event. ……………………….. ………..

7 2.2 Where to place JavaScript: Using in body section ensures that JavaScript is executed when page loading goes to body section. implementation: to generate content of page. ……… ………………………..

8 2.3 Where to place JavaScript: Using external JavaScript. JavaScript file is saved as.js file. But JavaScript file is without tags. Advantage: same script can be used for various pages. ……………….

9 3.1 More on JavaScript: using tags in java Scripts. document.write(“ this is header ”); document.write(“ this is paragraph ”); grouping statement in blocks. { document.write(“ this is header ”); document.write(“ this is paragraph ”); }

10 3.2 More on JavaScript: Single Line Comment. //this is simple line comment. multi-line Comments. /* This is multi-line comment. */

11 3.3 More on JavaScript: Declaring variables. var n1; var n2=10.5; var n3="number"; var n4='y'; var n5; n1=5; n5=n2-n1;

12 4 Operators: Assignment; used to assign value. var n1=2; var n2=4; n2+=n1; n2-=n1; n2*=n1; n2/=n1; n2%=n1;

13 Arithmetic and Logical. o Arithmetic Operators are; +, -, *, / and %. Note: + operator is also used for string concatenation. var n1=“it is ”; var n2=“very cold.”; document.write(n1+n2); o Logical Operators; determines logic between two values. (&&, ||, !) Example; If (x>10 && y<5) document.write( “x is greater than y.”);

14 Comparison operator; used to determine equality or difference between two expressions. e.g. x>y; x= = y;x<=y;x!=y; etc. Conditional Operators; are used to assign value to a varible based upon condition. Var_name=(condition)? Value1:value2; e.g. Error_msg=(age<18)? “too young”: “Age is ok”; n1=(n2>5)?10:5;


Download ppt "TECH 2018 (Week 16) Topic: JavaScript Parminder Kang Home: Phones Off Please."

Similar presentations


Ads by Google