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
// **** GLOBAL STATE OBJECT **** | |
var state = { | |
items: [], | |
}; | |
// **** HTML TO RENDER **** | |
var listItemTemplate = | |
'<li>' + |
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Thinkful | Text analyzer example solution</title> | |
<meta charset="utf-8" /> | |
<meta | |
name="description" | |
content="Exemplary solution for the text analyzer project from Thinkful's Front End Web Development course" | |
/> |
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
// Example 1: ECHO ENDPOINT | |
'use strict' | |
const express = require('express'); | |
const app = express(); | |
app.get('/echo/:what', (req, res) => { | |
res.json({ | |
host: req.hostname, | |
path: req.path, | |
query: req.query, |
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 express = require('express'); | |
const queryString = require('query-string'); | |
const app = express(); | |
const USERS = [ | |
{ | |
id: 1, | |
firstName: 'Joe', | |
lastName: 'Schmoe', | |
userName: 'joeschmoe@business.com', |
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
# GET ALL | |
# Command that retrieves all restaurants | |
$ db.restaurants.find(); | |
# LIMIT AND SORT | |
# Find the command that makes the first 10 restaurants appear alphabetically by 'name' | |
$ db.restaurants. | |
find(). | |
sort({name:1}). | |
limit(10); |
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
// Array Ex 6 | |
function makeList(item1, item2, item3) { | |
return [item1,item2,item3]; | |
} | |
// tests | |
function testMakeList() { | |
var items = ["prime rib", "fried goat cheese salad", "fish tacos"]; | |
var result = makeList(items[0], items[1], items[2]); | |
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 obj1 = { | |
key1: 1, | |
key2: 'Value2', | |
key3: 3, | |
key4: 'Value4' | |
} | |
var obj2 = { | |
key1: 1, | |
key2: 'Value2', |
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
What is scope? Your explanation should include the idea of global vs. local scope. | |
SCOPE IS THE UMBRELLA OR ROOM WHERE THE JS INTERPRETER IS LOOKING FOR VARIABLES TO USE, THESE COULD BE | |
IN THE GLOBAL SCOPE WHICH COULD BE THE UMBRELLA FOR MANY FUNCTIONS IN MANY FILES OR IT COULD BE LOCAL, | |
WHICH WOULD BE IN JUST A BLOCK OF INSTRUCTIONS FOR ONE FUNCTION | |
Why are global variables avoided? | |
THEY CAN BE HARD TO TRACK IF THERE'S ALOT OF SCRIPT TO SEARCH ON AND COULD CAUSE BUGS | |
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
// jQuery example | |
function main() { | |
try { | |
doAllTheThings(); | |
} | |
catch(e) { | |
console.error(e); | |
reportError(e); | |
} | |
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 computeArea(width, height) { | |
return width*height | |
} | |
function testComputeArea() { | |
var width = 3; | |
var height = 4; | |
var expected = 12; | |
if (computeArea(width, height) === expected) { | |
console.log('SUCCESS: `computeArea` is working'); |
NewerOlder