Skip to content

Instantly share code, notes, and snippets.

View michaelablackham's full-sized avatar

Michaela (Blackham) Lederman michaelablackham

View GitHub Profile
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<script id="jsbin-javascript">
@michaelablackham
michaelablackham / shouter
Created April 9, 2017 02:51
String Drills
function shouter(whatToShout) {
return whatToShout.toUpperCase() + '!!!';
}
/* From here down, you are not expected to
understand.... for now :)
Nothing to see here!
function computeArea(width, height) {
return width*height;
}
// tests
function testComputeArea() {
var width = 3;
var height = 4;
var expected = 12;
function main() {
try {
doAllTheThings();
}
catch(e) {
console.error(e)
reportError(e);
}
}
https://jsbin.com/batotex/1/edit?js,console
https://jsbin.com/jazemoh/1/edit?js,console
https://jsbin.com/nunojug/1/edit?js,console
https://jsbin.com/geyuyek/1/edit?js,console
https://jsbin.com/calogo/1/edit?js,console
https://jsbin.com/gemexah/edit?js,console
https://jsbin.com/lixoqim/1/edit?js,console
https://jsbin.com/kuqosim/1/edit?js,console
https://jsbin.com/nezazu/1/edit?js,console
https://jsbin.com/juhojo/1/edit?js,console
https://jsbin.com/sekihux/2/edit?js,output
https://jsbin.com/tevuri/2/edit?js,console
https://jsbin.com/mokuci/edit?js,console
1. What is scope? Your explanation should include the idea of global vs. local scope.
- Scope is the way the the browser parses the information on the page. It is like a backward ladder that first looks
within the function, then steps back and looks within the parent, etc.
- global scope is a variable that is defined within the body or outside of a function and is then avaiable everywhere
within your site
- local scope is a variable defined within that current function. This can be the same variable from the body, but is
only relevent to that current function
2. Why are global variables avoided?
- Global variables should be avoided so that no unintended side effects happen within the code. This makes it available
everywhere in the code, which then becomes a bit difficult to maintain.
https://jsbin.com/qaloxo/1/edit?js,console
https://jsbin.com/kokidav/edit?js,console
https://jsbin.com/fiwevut/1/edit?html,js,output
https://jsbin.com/dejiyo/1/edit?js,console
@michaelablackham
michaelablackham / Challenge: analyze a most frequent word program
Created April 26, 2017 04:04
Challenge: analyze a most frequent word program
function getTokens(rawString) {
// NB: `.filter(Boolean)` removes any falsy items from an array
return rawString.toLowerCase().split(/[ ,!.";:-]+/).filter(Boolean).sort();
/*returns a raw string, converts to lower case, splots the words/letters
by the user of spaces, commas, exclamation points, periods quotes,
semicolons, colons, hyphens and sort them in alphabetical order after
finding out if it is true or not*/
}
function mostFrequentWord(text) {
https://jsbin.com/walejod/edit?js,console
https://jsbin.com/deworib/3/edit?js,console
https://jsbin.com/qijepap/1/edit?js,console -- no idea what I was supposed to be finding for this one. need help talking this one out.
https://jsbin.com/borecug/edit?js,console -- even when running this one which i copied and pasted from the solution i still get an error
github: https://github.com/michaelablackham/thinkful-object-drills-2