This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async function myFunc() { | |
const promise = new Promise((resolve, reject) => { | |
setTimeout(() => resolve('Hello'), 1000); | |
}); | |
const err = false; | |
if (!err) { | |
const res = await promise; // wait until promise is resolved | |
return res; | |
} else { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* EasyHTTP Library | |
* Library for making HTTP requests | |
* | |
* @version 2.0.0 | |
* @author Eric Whale | |
* @license MIT..? | |
*/ | |
class EasyHTTP { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ajax+XHR -> fetch API | |
document.getElementById('button1').addEventListener('click', getText); | |
document.getElementById('button2').addEventListener('click', getJson); | |
document.getElementById('button3').addEventListener('click', getExternal); | |
// Get local txt data | |
function getText() { | |
fetch('test.txt') | |
.then(res => res.text()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const posts = [ | |
{ title: 'Post one', body: 'this is post one' }, | |
{ title: 'Post two', body: 'this is post two' } | |
]; | |
function createPost(post) { | |
return new Promise(function (resolve, reject) { | |
setTimeout(function () { | |
posts.push(post); | |
const error = false; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function easyHTTP() { | |
this.http = new XMLHttpRequest(); | |
} | |
// Make an HTTP GET Request | |
easyHTTP.prototype.get = function (url, callback) { | |
this.http.open('GET', url, true); | |
let self = this; | |
this.http.onload = function () { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// XHR (xmlHTTPrequest) - JSON --------------------------------------------------------------------- | |
document.getElementById('button2').addEventListener('click', loadCustomers); | |
function loadCustomers(e) { | |
const xhr = new XMLHttpRequest(); | |
xhr.open('GET', 'customers.json', true); | |
xhr.onload = function () { | |
if (this.status === 200) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Book Constructor | |
function Book(title, author, isbn) { | |
this.title = title; | |
this.author = author; | |
this.isbn = this.isbn; | |
} | |
// UI Constructor | |
function UI() {} | |
UI.prototype.addBookToList = function (book) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Person(firstName, lastName) { | |
this.firstName = firstName; | |
this.lastName = lastName; | |
} | |
Person.prototype.greeting = function () { | |
return `Hello there ${this.firstName} ${this.lastName}`; | |
}; | |
const person1 = new Person('John', 'Doe'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Object prototype | |
// | | |
// Person prototype | |
// | | |
// Person instance ex) john | |
// Constructor | |
function Person(firstName, lastName, dob) { | |
this.firstName = firstName; | |
this.lastName = lastName; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
GAME FUNCTION: | |
- Player must guess a number between a min and max | |
- Player gets a certain amount of guesses | |
- Notify player of guesses remaining | |
- Notify the player of the correct answer if loose | |
- Let player choose to play again | |
*/ | |
// Game values |