Skip to content

Instantly share code, notes, and snippets.

View avand's full-sized avatar

Avand Amiri avand

View GitHub Profile
<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>
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);
}
// 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"
var user = { "login": "avand", "id": 12224 };
var jsonString = JSON.stringify(user); // => '{ "login": "avand", ... }'
// Using '' here to avoid conflicts with the "" in the string...
var user = '{ "login": "avand", "id": 12224 }';
user.login; // => undefined
user.length; // => 33
// 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",
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...
}
// 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"
var user = {
firstName: "Avand",
lastName: "Amiri",
getFullName: function() {
return this.firstName + " " + this.lastName;
}
}
// 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