教学文库网 - 权威文档分享云平台
您的当前位置:首页 > 文库大全 > 资格考试 >

INFO1003_Foundamental of IT_2012 Semester 2_Lecture5.2_Javas

来源:网络收集 时间:2026-09-02
导读: University of Sydney_INFO1003_Foundamental of IT_2012 Semester 2 26/08/2012 Foundations of IT (INFO1003)Semester 2, 2012 Lecture 5.2– Javascript Scripting 1 Schedule 2 University of Sydney_INFO1003_Foundamental of IT_2012 Semester 2 26/08

University of Sydney_INFO1003_Foundamental of IT_2012 Semester 2

26/08/2012

Foundations of IT (INFO1003)Semester 2, 2012

Lecture 5.2– Javascript Scripting 1

Schedule

2

University of Sydney_INFO1003_Foundamental of IT_2012 Semester 2

26/08/2012

Agenda Previously with HTML- Appreciate pp some of the requirements q of user interface design g - Draw useful conclusions from guidelines for interface design suggested by researchers - Make appropriate use of the interface elements available for effective form/page design - Cascading Style Sheets (CSS)

This week- Introduction to Javascript - Variables& Data Types - Program Tracing

3

What is computer programming? What is Programming? The process or steps involved to get a device to perform a desired task Computer programming: are the step by step instructions that tell the computer how to solve a problem or carry out a specific task(s). You write programs by giving precise instructions in a programming language.

4

University of Sydney_INFO1003_Foundamental of IT_2012 Semester 2

26/08/2012

What is JavaScript? Scripting Language JavaScript is available in two formats: client-side client side JavaScript and server-side JavaScript. Client-side execution refers to a program running on a local browser (the client) instead of on a server. Gives web pages more interactivityAnimations Actions responding to user input Form Validation Control look and feel of browser Managing Cookies5

JavaScript Syntax JavaScript is encoded inside your HTML Document. <script> and</script> to tell where the JavaScript starts and ends– also called“a a script block” block .<html><head><title> My JavaScript Page</title><script> some JavaScript Codes... ...</script></head><body><h1> Your first JavaScript Program</h1><script> some JavaScript Codes...</script></body></html>6

University of Sydney_INFO1003_Foundamental of IT_2012 Semester 2

26/08/2012

My First JavaScript Consider the keyword alert: a standard JavaScript command that will cause an alert box to pop up on the screen.<html><head><title> My JavaScript Page</title><script> alert(“Greetings INFO 1003 Student!”);</script></head><body><h1> Your first JavaScript Program</h1></body></html>

Note: Always a good practice to put semicolon (;) at the end of each line.

7

8/28

University of Sydney_INFO1003_Foundamental of IT_2012 Semester 2

26/08/2012

Variables Variables are used to store a value for your program. Declaring a variable- You can create a variable with the var keyword: yvar total= 100;

- You can also create a variable without the var statement:total= 200; (less preferred!!)

Examples: p<script>var i= 10; var s=“Testing”;</script>

9

JavaScript Data TypesTypeNumbers

DescriptionAre values that can be processed and calculated. You don't don t enclose them in quotation marks. The numbers can be either positive or negative. They can also be integers or floating point. Series of letters and numbers enclosed In Single or double quotation marks. You'll use strings for text you want displayed or values you want passed along. true or false

Examplevar I= 17; var j= 21; var k= -10.005;

Strings

var a=“Hello”; var b=‘goodbye’;

Boolea

n Null is an empty value. Not the same as 0 or“” null is the absence of any value.

var c= true; var d= false; var x= null;

Unlike Java or other programming languages, you do not need to explicitly declare the data type in JavaScript.10

University of Sydney_INFO1003_Foundamental of IT_2012 Semester 2

26/08/2012

Rules for Variable Names Variable names are case sensitivei e var abc is different from var ABC i.e.

They must begin with a letter or the underscore character Spaces are not allowed inside variable names You Y cannot t used d a reserved d word df for a variable i bl name, i.e. alert

11

Rules for Variable Names Exercise, which of the following are not valid variable names: 1. var krazy 2. var$tupid 3. var illegal_var 4. var _another_illegal_var 5. var 1234One

12

University of Sydney_INFO1003_Foundamental of IT_2012 Semester 2

26/08/2012

Naming Variables Give each variable name, a meaningful name. The previous variable abc is a bad example. Bad names include:- S, c, n, a, av, somevar, myvar, this, that, blah, foo

Good names include:- firstName, myAddress, meanGrade - Good variable names should describe the data being stored.13

JavaScript Operators Operators are used to operate on values.Operator+ */% Description Addition Subtraction Multiplication Division Modulus (division remainder) Increment (by one) Decrement (by one) Example var x=2; x= x+2; var x=2; x= 5-x; var x=4; x= x*5; var x= 15; x= 15/ x; var x= 5%2; var x= 10%8; var x= 10%2; var x=5; x++; var x=5; x--; Value of X 4 3 20 1 1 2 0 6 4

++ --

14

University of Sydney_INFO1003_Foundamental of IT_2012 Semester 2

26/08/2012

Changing Variable Values The value of the variable can be changed at any time.

<script> var i= 10; var j= 15;… after some codes… i= 50; j= i+5;</script>

i 10 50 j 15 5515

Variable (Tracing) ExerciseQ1. What happens in the following code:<script> var x= 10;; var y=“INFO1003”; var z= 30; x= x+ z; a= x+ y; z= x+ z;</script> What is x x, y y, z and a?

16

University of Sydney_INFO1003_Foundamental of IT_2012 Semester 2

26/08/2012

Output What is the output of the following program:

<script> var x= 10; var y= 20; document.write(“x=“+x); alert(“y=“ …… 此处隐藏:4761字,全部文档内容请下载后查看。喜欢就下载吧 ……

INFO1003_Foundamental of IT_2012 Semester 2_Lecture5.2_Javas.doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.jiaowen.net/wenku/91005.html(转载请注明文章来源)
Copyright © 2020-2025 教文网 版权所有
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:78024566 邮箱:78024566@qq.com
苏ICP备19068818号-2
Top
× 游客快捷下载通道(下载后可以自由复制和排版)
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能出现无法下载或内容有问题,请联系客服协助您处理。
× 常见问题(客服时间:周一到周五 9:30-18:00)