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
<form> | |
<input type="search" id="query" placeholder="GitHub username"> | |
<input type="submit" value="Lookup"> | |
</form> | |
<table> | |
<tr> | |
<th>Name:</th> | |
<td id="user-name"></td> | |
</tr> |
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
var request = new XMLHttpRequest(); | |
request.open("GET", "https://api.github.com/users/avand", true); | |
request.addEventListener("readystatechange", handleReadyStateChange) | |
function handleReadyStateChange() { | |
if (request.readyState == 4 && request.status == 200) { | |
console.log(request.responseText); | |
} |
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
// Load jQuery 2.2.4 from Google's servers (they host it for free)... | |
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script> | |
<script> | |
// Call get with a URL and provide a function to call when the results come back... | |
$.get("https://api.github.com/users/avand", handleResponse); | |
// Define the callback function... | |
function handleResponse(user) { | |
console.log(user.name); // => "Avand Amiri" |
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
var user = { "login": "avand", "id": 12224 }; | |
var jsonString = JSON.stringify(user); // => '{ "login": "avand", ... }' |
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
// Using '' here to avoid conflicts with the "" in the string... | |
var user = '{ "login": "avand", "id": 12224 }'; | |
user.login; // => undefined | |
user.length; // => 33 |
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
// Visit: https://api.github.com/users/avand | |
// Change "avand" to your GitHub user name. | |
{ | |
"login": "avand", | |
"id": 12224, | |
"avatar_url": "https://avatars.githubusercontent.com/u/12224?v=3", | |
"gravatar_id": "", | |
"url": "https://api.github.com/users/avand", | |
"html_url": "https://github.com/avand", |
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
assignments.forEach(listAssignment); | |
function listAssignment(assignment) { | |
var assignmentName = assignment.name; | |
var assignmentDescription = assignment.description; | |
var assignmentDueDate = assignment.dueDate; | |
// Do whatever you want now with those values... | |
} |
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
// Instead of having data split up across arrays... | |
var assignmentNames = ["ACME Corp", "Likes & Comments", "Todo List"]; | |
var assignmentDescriptions = ["Implement the design for ACME Corp.", "Build a couple social widgets.", "Build a simple todo list program."]; | |
var assignmentDueDates = ["Jan 1", "Jan 7", "Jan 14"]; | |
// Keep each assignment together in an object... | |
var assignment1 = { | |
name: "ACME Corp", | |
description: "Implement the design for ACME Corp.", | |
dueDate: "Jan 1" |
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
var user = { | |
firstName: "Avand", | |
lastName: "Amiri", | |
getFullName: function() { | |
return this.firstName + " " + this.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
// Let's say you have a few items in a string | |
// separated with commas... | |
var s = "dog, cat, fish"; | |
// You can convert that string into an array of | |
// strings by splitting on a delimiter, in this | |
// case the delimiter is a comma followed by a space... | |
var a = s.split(", "); | |
// Now a is ["dog", "cat", "fish"]. And you can |