INFO1003_Foundamental of IT_2012 Semester 2_Lecture5.2_Javas
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字,全部文档内容请下载后查看。喜欢就下载吧 ……
相关推荐:
- [资格考试]石油钻采专业设备项目可行性研究报告编
- [资格考试]2012-2013学年度第二学期麻风病防治知
- [资格考试]道路勘测设计 绪论
- [资格考试]控烟戒烟知识培训资料
- [资格考试]建设工程安全生产管理(三类人员安全员
- [资格考试]photoshop制作茶叶包装盒步骤平面效果
- [资格考试]授课进度计划表封面(09-10下施工)
- [资格考试]麦肯锡卓越工作方法读后感
- [资格考试]2007年广西区农村信用社招聘考试试题
- [资格考试]软件实施工程师笔试题
- [资格考试]2014年初三数学复习专练第一章 数与式(
- [资格考试]中国糯玉米汁饮料市场发展概况及投资战
- [资格考试]塑钢门窗安装((专项方案)15)
- [资格考试]初中数学答题卡模板2
- [资格考试]2015-2020年中国效率手册行业市场调查
- [资格考试]华北电力大学学习实践活动领导小组办公
- [资格考试]溃疡性结肠炎研究的新进展
- [资格考试]人教版高中语文1—5册(必修)背诵篇目名
- [资格考试]ISO9001-2018质量管理体系最新版标准
- [资格考试]论文之希尔顿酒店集团进入中国的战略研
- 全国中小学生转学申请表
- 《奇迹暖暖》17-支2文学少女小满(9)公
- 2019-2020学年八年级地理下册 第六章
- 2005年高考试题——英语(天津卷)
- 无纺布耐磨测试方法及标准
- 建筑工程施工劳动力安排计划
- (目录)中国中央空调行业市场深度调研分
- 中国期货价格期限结构模型实证分析
- AutoCAD 2016基础教程第2章 AutoCAD基
- 2014-2015学年西城初三期末数学试题及
- 机械加工工艺基础(完整版)
- 归因理论在管理中的应用[1]0
- 突破瓶颈 实现医院可持续发展
- 2014年南京师范大学商学院决策学招生目
- 现浇箱梁支架预压报告
- Excel_2010函数图表入门与实战
- 人教版新课标初中数学 13.1 轴对称 (
- Visual Basic 6.0程序设计教程电子教案
- 2010北京助理工程师考试复习《建筑施工
- 国外5大医疗互联网模式分析




