close

Вход

Забыли?

вход по аккаунту

?

JavaScript I/O, subroutines and functions

код для вставкиСкачать
18 March
2014
п‚Ё
Form names and input ids MUST BE UNIQUE
п‚Ё
<input> tag does not need end tag
п‚Ё
п‚Ё
Inside attributes like onclick
As a section of code in the body
п‚Ў
п‚Ё
May need this later
As a function in a separate file
п‚Ў
Can link to it like the css
п‚Ё
п‚Ё
п‚Ё
п‚Ё
Collection of statements that can be invoked as
a unit
Like the built-in functions in Excel, but YOU
define it
Can take parameters
Can return values
function name() {
stmt;
stmt;
}
function name(parms) {
stmt;
stmt;
}
<script src="myscripts.js"></script>
Myscript.js
JavaScript option in komodo
note that it’s an empty file
but it can help you
do NOT include the script tag
п‚Ё
Like Excel cells
Hold values
п‚Ў Refer to the location, not the value
п‚Ў Different behavior depending on content
п‚Ў Need to give them values (assignment)
п‚Ў
п‚Ё
Explicitly define them
п‚Ў
п‚Ё
п‚Ё
Can give them starting values
Figures out type
Case sensitive
var x = 5; (note: this is the ONLY use of =)
п‚Ё
п‚Ё
Different types of data -> different actions
 We can add numbers; we can’t add words
Excel data types
п‚Ў Number
п‚Ў Text (String)
п‚Ў True/False (Boolean)
п‚Ў Array
п‚Ў Error
п‚Ў Date
п‚Ё
JavaScript data types
п‚Ў Number
п‚Ў Text (String)
п‚Ў True/False (Boolean)
п‚Ў Array
п‚Ў Null
п‚Ў Object
п‚Ё
п‚Ё
п‚Ё
п‚Ё
Collection of related information
Easy way to choose between items
var array = [ “A", "B", “F", "G" ];
array[index]
WRONG TYPE: ERROR OR BAD ANSWER
Examples of Error
Excel:
=ROUND(“two”,2)
#VALUE!
JavaScript
=Math.round(“two”)
NaN (Not a Number)
Bad Answer
JavaScript
Add Strings
“3”+”5”
35
Add Numbers
3+5
8
п‚Ё
Overload:
п‚Ў
п‚Ё
п‚Ё
different meanings for numbers and strings
A common action: add or concatenate to a
variable
+= operator
п‚Ў
п‚Ў
a += b
a=a+b
п‚Ё
п‚Ё
Can write to an input field as well as read it
Don’t want it to look like a box?
п‚Ў
п‚Ў
Transparent background
No border
Документ
Категория
Без категории
Просмотров
7
Размер файла
256 Кб
Теги
1/--страниц
Пожаловаться на содержимое документа