notes on facts and random tags
- WWW invented in 1989
- 1994 onwards W3C world wide web consortium
emphasis
harder things to code:
| multiple | 3 | 4 |
|---|---|---|
| 5 | 15 | 20 |
| 6 | 18 | 24 |
simple coding things:
JavaScript notes
html is (declerative) describes how things should be do this do that. code>compile>run>repeat
javascript is procedural describes step-by-step. Interpreted language code>run>repeat. weakly typed
primtive data type way of defining and grouping values that cant be changed
these are number,string,boolean,undefined,null,bigInt,symbol
non prmitive are array and object (immutuable) cant change but can reassign
/ is div % is modulo the thing to find remainders 0.5->1 so odd
console.log(typeof 42); returns number finds the type of data.
&& - AND || - OR ! - NOT
String.charAt() find where a letter is the index
String.indexOf() if the substring cant be found -1 is returned.
String.toLowerCase() String.length()
String.trim() removes white spaces
String.substr(index,length) returns part of a string starting at index
string.split(" ") breaks a string up into an array. this example is one word per index
string.startsWith() if the string typed in if it starts like that returns True. string.endsWith()
function multiply(x=1,y=2) {return x*y}; console.log(multiply(7,8)) default paramteres are 1 and 2
var has local/global scope and is hoisted. let has block scope and is not hoisted
array.unshift() - add elemts to start of an arry and returns value. opposite of push
array.shift() - removes first elements returns. opposite of pop()
array.join() - joins the things into a String
array.map() coding
array.filter() - creates new array with all elements that pass the test to be implemented by the provided function
week 10 and 11 DOM notes
DOM stands for Document Object Model
Lets JavaScript access, add, remove, or change things in the HTML and CSS
The DOM is a tree structure made from the HTML when the page loads
Everything in the HTML becomes a node (elements, text, attributes)
Ways to access elements:
document.getElementById("id") – gets one element with that ID
document.getElementsByClassName("class") – gets a list of elements with that class
document.getElementsByTagName("tag") – gets all elements of that type
document.querySelector("selector") – gets the first element that matches a CSS selector
document.querySelectorAll("selector") – gets all elements that match a CSS selector
querySelector uses CSS rules (use # for id and . for class)
Once you have an element, you can get or change its content with element.textContent
You can also get or set attributes with element.getAttribute() and element.setAttribute()
You can’t access the DOM until it’s fully loaded
The browser loads HTML line by line and runs JavaScript as it sees it
If JavaScript runs too early, it might not find the element yet
Two ways to fix this:
1. Use the load event:
window.addEventListener("load", function() {document.querySelector("#target");});
2. Put the script at the bottom of the HTML page before