Skip to content

Instantly share code, notes, and snippets.

View prof3ssorSt3v3's full-sized avatar
🎯
Focusing

Steve Griffith prof3ssorSt3v3

🎯
Focusing
View GitHub Profile
// nested loops and multi-dimensional objects
// We can use nested loops to access all the elements
// inside multi-dimensional arrays or objects
let twoD = [[1, 2, 3, 4, 5, 6, 7],
[8, 10, 5, 7, 3, 22, 6, 42],
[123, 54, 12, 11, 9, 15]];
let bigHero = {characters:[
{name:'Hiro', voice:'Ryan Potter'},
//fetch using a Request and a Headers objects
//using jsonplaceholder for the data
const uri = 'http://jsonplaceholder.typicode.com/users';
//new Request(uri)
//new Request(uri, options)
//options - method, headers, body, mode
//methods: GET, POST, PUT, DELETE, OPTIONS
// JavaScript Event Listeners
// Event-driven programming: your program waits for events and uses them as triggers to run the next function(s)
//
document.addEventListener('DOMContentLoaded', init);
function init(){
let btn = document.getElementById('btn');
let lnk = document.getElementById('lnk');
let txt = document.getElementById('txt');
// Unicode Characters in JavaScript
// Escape Sequences in JavaScript
// http://www.unicode.org/charts/
// String.fromCharCode(num [, num, num])
// myString.charCodeAt(index)
// \u0434
// \0 \' \" \\ \n \r \t
//
// Keyboard events in the Browser
//ev.char || ev.charCode || ev.which
// keydown keyup keypress
let log = console.log;
document.addEventListener('DOMContentLoaded', init);
function init(){
let txt = document.getElementById('txt');
// Event Bubbling and Propagation
// element.addEventListener( type, func, useCapture);
let m = document.getElementById('m');
let d = document.getElementById('d');
let p = document.getElementById('p');
let s = document.getElementById('s');
let log = console.log;
let highlight = (ev)=>{
// While loops
//
// while(condition){
// statements
// }
//
// do{
// statements
// }while(condition)
//namespace1.js
let STEVE = {
colorDiv: function(ev){
let target = ev.currentTarget;
target.style.backgroundColor = 'purple';
target.style.color = 'white';
},
init: function(){
let divA = document.getElementById('output');
//geolocation.js
// How to use Navigator.geolocation
//
let G, options, spans;
document.addEventListener('DOMContentLoaded', init);
function init(){
if(navigator.geolocation){
let giveUp = 1000 * 30; //30 seconds
// Web Storage
// localStorage
// sessionStorage
// JSON
// setItem()
// getItem()
// clear() - erase everything
// removeItem( key ) - delete one item
// key( index ) - get the name of one item