JavaScript.3 2012. Встроенные объекты String Math Date.

Slides:



Advertisements
Similar presentations
В проекте рассмотрены функции даты и времени: текущие дата и время, день недели, день месяца, день года, проверка на високосный год, максимальное и минимальное.
Advertisements

Modern JavaScript Develop And Design Instructor’s Notes Chapter 6 - Complex Variable Types Modern JavaScript Design And Develop Copyright © 2012 by Larry.
Session 8 JavaScript/Jscript: Objects Matakuliah: M0114/Web Based Programming Tahun: 2005 Versi: 5.
Strings, Math and Dates JavaScript. 2 Objectives How to modify strings with common string method When and how to use the Math Object How to use the Date.
Math Meeting What is today’s date? __________________________ What was the date 2 months ago? ________________ What season was it ?___________________________.
Язык JavaScript Скриптовый язык для выполнения на html-страницах.
1 HCI 201 JavaScript - Part 1. 2 Static web pages l Static pages: what we have worked with so far l HTML tags tell the browser what to do with the content.
Arrays Create an array of strings var table = ["first", "second", "third"]; Print the third item alert(table[2]); Example IndexContents 0"first" 1"second"
Lecture 1 Term 2 9/1/12 1. Objects You normally use the “.” Operator to access the value of an object’s properties. The value on the left of the “.” should.
Формы в HTML. Элемент FORM Элемент уровня «блок» Управляющие элементы Просто текст Атрибуты: action – url обработчика method – post или get enctype –
Tutorial 11 Working with Operators and Expressions
Time & Date Representation in Java. Date class An object of type Date represents an instance in time Part of java.util.* (requires import statement) A.
JavaScript Objects Objects – JavaScript is an object-based language Has built-in objects we will use – You can create your own objects We concentrating.
Lesson 14.
JavaScript Events and Event Handlers 1 An event is an action that occurs within a Web browser or Web document. An event handler is a statement that tells.
Using Object-Oriented JavaScript CST 200- JavaScript 4 –
2 Alerts and the If/Else Conditional Statement CONTINUED There's No Right Way to Do It There are, literally, a million ways to write any given script.
Math Meeting Write today’s date. __________________________ What was the date 4 months & 1 day ago?___________________________ What season was it?
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting Includes and Dates.
The Web Wizard’s Guide To JavaScript Chapter 6 Working with Dates and Times.
Copyright ©2005  Department of Computer & Information Science Using Number & Math Objects.
JavaScript Functions & Objects. JavaScript Functions FunctionDescription decodeURI()Decodes an encoded URI decodeURIComponent()Decodes an encoded URI.
Objects.  Java Script is an OOP Language  So it allows you to make your own objects and make your own variable types  I will not be going over how.
ALBERT WAVERING BOBBY SENG. Week 5: More JavaScript  Quiz  Announcements/questions.
Math Meeting Write today’s date __________________________ Which months have 31 days? ___________________________________________________________________.
M. Taimoor Khan Javascript Objects  Every data-type defined in Javascript is an object  It has a class definition for.
Keeping it Neat: Functions and JavaScript Source Files Chapter 7.
Using Decimal Types. What are the data types that you can use? Decimal Number: Single -Is used for decimal values that will not exceed six or seven digits.
Math Meeting Write today’s date __________________________ Which months have 31 days? ______________________________________________________________________.
Garside, JAVA: First Contact, 2ed Java First Contact – 2 nd Edition Garside and Mariani Chapter 6 More Java Data Types.
XP Tutorial 2 New Perspectives on JavaScript, Comprehensive1 Working with Operators and Expressions Creating a New Year’s Day Countdown Clock.
ECA 225 Applied Interactive Programming ECA 225 Applied Online Programming javascript dates.
Math Meeting Write today’s date. ________________________ What was the date 8 months ago? ________________ What season was it ?___________________________.
COP 2510 Chapter 6 - Functions. Random function (randint) #import the desired function import random #integer random number in the range of 1 through.
A: A: double “4” A: “34” 4.
Math Meeting Write today’s date __________________________ July 4 th is Independence Day. On what day of the week is Independence Day this year? ___________.
Tutorial 11 1 JavaScript Operators and Expressions.
Chapter 9: Control Statements II CIS 275—Web Application Development for Business I.
Math Review 4 th Grade. Dates There are 52 weeks in one year. There are 365 days in one year. January, March, May, July, August, October, and December.
Math Meeting Write today’s date. _________________________ How many months are in 6 years? ___________________________ How many days are in 8 weeks?______________.
Working with Date and Time ISYS 475. How PHP processes date and time? Traditional way: – Timestamp Newer and object oriented way: – DateTime class.
IMS 3253: Dates and Times 1 Dr. Lawrence West, MIS Dept., University of Central Florida Topics Date and Time Data Turning Strings into.
JavaScript JavaScript ( Condition and Loops ). Conditional Statements If Statement If...else Statement if (condition) { code to be executed if condition.
JavaScript Tutorial. What is JavaScript JavaScript is the programming language of HTML and the Web Programming makes computers do what you want them to.
COM621: Advanced Interactive Web Development Lecture 5 – JavaScript.
JavaScript
HTML & teh internets.
JavaScript Objects.
SEEM4570 Tutorial 05: JavaScript as OOP
Java Script.
JavaScript Arrays Date
© Copyright 2016, Fred McClurg All Rights Reserved
Week#3 Day#1 Java Script Course
Java Date ISYS 350.
Review Operation Bingo
BY: SITI NURBAYA ISMAIL FACULTY of COMPUTER and MATHEMATICAL SCIENCES
البرمجة بلغة الفيجول بيسك ستوديو
Objects as Variables Featuring the Date Object
Tutorial 4 JavaScript as OOP Li Xu
Java Date ISYS 350.
SAT Practice Test.
Name _________________________ Date _______________
Kirkwood Center for Continuing Education
Java Date ISYS 350.
The Web Wizard’s Guide To JavaScript
Strings and Dates in JavaScript
Trainer: Bach Ngoc Toan– TEDU Website:
CSC 221: Introduction to Programming Fall 2018
Java Date ISYS 350.
Name _________________________ Date _______________
Presentation transcript:

JavaScript

Встроенные объекты String Math Date

String Var myString=“hello” Var myString=new String (“hello”)

Конкатенация document.write(“ of ” + navigator.appName + “.”) var msg = “Four score” msg = msg + “ and seven” msg = msg + “ years ago,” var msg = “Four score” msg += “ and seven” + “ years ago”

Методы объекта String var result = string.toUpperCase() var result = string.toLowerCase() var foundMatch = false if (stringA.toUpperCase() == stringB.toUpperCase()) { foundMatch = true }

Поиск подстроки var isWindows = false if (navigator.userAgent.indexOf(“Win”) != - 1) { isWindows = true }

Копирование символов и подстрок var stringA = “Building C” var bldgLetter = stringA.charAt(9) // result: bldgLetter = “C” var stringA = “banana daiquiri” var excerpt = stringA.substring(2,6) // result: excerpt = “nana”

Работа со строками var stringA = “The United States of America” var excerpt = stringA.substring(stringA.indexOf(“ “) + 1, stringA.length) // result: excerpt = “United States of America”

The Math Object var piValue = Math.PI var rootOfTwo = Math.SQRT2 var larger = Math.max(value1, value2) var result = Math.round(value1) Math.floor(Math.random() * (n + 1)) newDieValue = Math.floor(Math.random() * 6) + 1

The Date Object var today = new Date() var someDate = new Date(“Month dd, yyyy hh:mm:ss”) var someDate = new Date(“Month dd, yyyy”) var someDate = new Date(yy,mm,dd,hh,mm,ss) var someDate = new Date(yy,mm,dd) var someDate = new Date(GMT milliseconds from 1/1/1970)

Методы объекта Дата (1) dateObj.getTime() Milliseconds since 1/1/70 00:00:00 GMT dateObj.getYear() Specified year minus 1900; four- digit year for dateObj.getFullYear() Four-digit year (Y2K- compliant); version dateObj.getMonth() 0-11 Month within the year (January = 0) dateObj.getDate() 1-31 Date within the month dateObj.getDay() 0-6 Day of week (Sunday = 0) dateObj.getHours() 0-23 Hour of the day in 24-hour time dateObj.getMinutes() 0-59 Minute of the specified hour dateObj.getSeconds() 0-59 Second within the specified minute

Методы объекта Дата (2) dateObj.setTime(val) Milliseconds since 1/1/70 00:00:00 GMT dateObj.setYear(val) Specified year minus 1900; four- digit year for dateObj.setMonth(val) 0-11 Month within the year (January = 0) dateObj.setDate(val) 1-31 Date within the month dateObj.setDay(val) 0-6 Day of week (Sunday = 0) dateObj.setHours(val) 0-23 Hour of the day in 24-hour time dateObj.setMinutes(val) 0-59 Minute of the specified hour dateObj.setSeconds(val) 0-59 Second within the specified minute

Вычисление даты Date Calculation function nextWeek() { var todayInMS = today.getTime() var nextWeekInMS = todayInMS + (60 * 60 * 24 * 7 * 1000) return new Date(nextWeekInMS) } Today is: var today = new Date() document.write(today) Next week will be: document.write(nextWeek())

Упражнения 1.Создайте страницу, в которой имеется поле для ввода электронного адреса и кнопка Submit. Напишите сценарий, который проверяет, верен ли адрес перед отправкой содержимого полей формы. 2.Посчитайте, сколько дней, часов, минут и секунд вы живете на свете? 3.Посчитайте с учетом високосных годов. 4.Напишите сценарий, который при нажатии на кнопку в двух текстовых полях выводит случайные целые числа от 4 до 17, а в третьем поле выводит произведение этих чисел.