JavaScript Flashcards

1
Q

Benefits of JavaScript

A
  • user input (mouse, keyboard, etc.)
  • modify HTML elements and CSS dynamically (change styles, etc.)
  • analyze data like user input (validating form input, etc.)
  • change content based on specific conditions (diff message for student vs teachers, etc.)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

JavaScript

A
  • use variable names
  • several types of variables: string, integer, float/double, array
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Arrays

A
  • indexes such that each item has a position, starting at 0
  • access individual elements using square brackets and an index
  • ie Boolean and arrays, if colors = [“red”,”blue”]
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

JS and CSS

A
  • directly change element styles
  • change classes or IDs
  • advanced animations/transitions
  • content can also be changed
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

document.getElementBy__()

A
  • ById, TagName, or ClassName
  • ID element getter is the best one to use since it returns one specific object
  • getting elements by tag or class may be helpful in specific cases in which an array of elements need to be accessed at once
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

dot notation

A
  • accessing levels of properties, so styles can be modified
  • style is a property in HTML elements
  • CSS styles are properties within style
  • element.style.styleproperty
  • eg. md.style.width
  • after specifying a style, use ‘=’ and set the new value in quotation marks
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

camel case

A
  • equivalent to style properties that contain a hyphen in CSS
  • backgroundColor = background-color
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

HTML to JSS class change options
HTML: div id=”tb” class=”box”
JS: var tb = document.getElementbyId(“tb”);
tb.className = “newbox”;
tb.className = “box newbox”;

A
  • single class is usually a replacement
  • multiple classes are usually additions
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Event handling - event listeners

A
  • style/content changes will typically be done as a result of an event
  • user input events: mouse-based, keyboard-based
  • load event
  • timer events
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

2 main ways to add event listeners

A
  • inline: attach event listener as an attribute in the HTML element tag
  • dot notation: use the addEventListener() function as a property on the element using dot notation
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Inline event listener

A
  • starts with “on” followed by an event name
  • eg. onclick, onmouseover, onmouseout, onfocus (focus on form field), onblur (leave a form field)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

2 types of timer events

A
  • timeout: trigger a function once after a specified time has elapsed
  • interval: trigger a function repeatedly in intervals of the specified time
  • setTimeout(function, ms) or setInterval(function, ms)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Conditionals

A
  • portions of code will only execute if specific conditions are met
  • if-else statements are used
  • combined them with && (and) operator or use ||(or) operator
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Functions

A
  • process that can be executed at any time, and any number of times
  • call function –> myFunction();
  • have input parameters which are placed within parentheses
  • parameters make the function reusable and flexible to work in different scenarios
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

what are the parameters to function average (x,y) {
var z = (x+y)/2;
document.write(“result: “ + z);
}

A

x and y

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

Loops

A
  • run code repeatedly in a row
  • while-loop and for-loop
  • contains 3 parts: variable initialization, condition, increment
17
Q

Form modifications

A
  • hiding/showing fields
  • changing the set of available options in a dropdown menu list
  • automatically checking a series of checkboxes
18
Q

show/hide a form field

A
  • changing display style
  • x.style.display = “none”;
  • x.style.display = “block”;
19
Q

Add a new text input box into the “con” container

A

var x = document.createElement(“input”)
x.type = “text”;
x.className = “contact”;
x.id = “provinceBox”;
var c = document.getElementById(“con”);
c.appendChild(x);

20
Q

validate web forms

A
  • ‘maxlength’ and ‘required’ attributes
  • real-time validation: keypress/onkeyup, onblur
  • submission-time validation: onclick/onsubmit
21
Q

get input to examine for validation

A
  • get elements by ID/class/tag
  • use dot notation to retrieve the value of that element
  • for text, password, and textarea, use element.value
  • for radio button and checkboxes, use element.checked
22
Q

isNaN() function

A

checks if value is Not a Number