Web Programming - Week 3 Flashcards

1
Q

What are HTML Events

A

Activities performed by user to control the page which can execute JavaScript code

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Syntax of defining an event attribute

A

< element eventname = code >

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Common HTML events

A
onchange
onclick
onmouseover
onmouseout
onkeydown
onload
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How to define an object

A
var ObjectName = new Object();
OR
var ObjectName = {..} comma instead of semi colon
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the purpose of “this” in a function

A

Refers to the owner of the function

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

JavaScript prebuilt objects

A
Array - Makes a list with [] or ()
Date - (YY/MM/DD)
Maths
String
Number
JSON
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Common String Methods

A

length
indexOf(string)
toUpperCase()
trim()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Common Number Methods

A

toString()
toFixed(number)

Number()

parseInt()
parseFloat()
isNan()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Common Array Methods

A

toString()
join(separator)

pop() - Removes and returns last value
push() - Adds new value
shift() - Removes first value

unshift() - Adds new element at beginning
reverse()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Syntax of calling sort

A

arr.sort([compareFunction])

compareFunction defines alternative sort order

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Compare Function Structure

A

array.sort(function(a,b){
return a - b;
});

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Arrow Compare Function Structure

A

array.sort((a,b) => a - b);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Common Math Methods

A
PI
round()
min()
max()
random()
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Creating a Date object

A
new Date(); - Today's date
new Date(year, month, day, hours...)
new Date(dateString);
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Common Date Methods

A

getFullYear()
getMonth()
toString()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

JSON syntax

A

{“property”:value, “property”:value, etc.}

17
Q

Two important JSON methods

A

JSON.stringify() - Converts object to string

JSON.parse() - Converts string to object

18
Q

What is a property

A

A value that you can get or set

19
Q

What is a method

A

An action that you can do

20
Q

Document Object Methods

A

document.getElementById(ObjectID)

var element = document.getElementById(ObjectID);

document.getElementsByTagName(name)

var paragraph = document.createElement(“p”);

var element = document.getElementByClassName(Classname)

21
Q

What does querySelector() do

A

Returns the first element that matches a specified CSS Selector(s) in the document

22
Q

What does document.querySelector(“p.myP”) do

A

Returns the first paragraph with class “myP”

23
Q

What does querySelectorAll() do

A

Returns all elements that match a specified CSS Selector(s) in an array

24
Q

What is the syntax for an event listener for an existing function

A

element.addEventListener(event,function_name);

25
Q

What is the syntax for an event listener for a new function

A

element.addEventListener(event, function(){

});