Skip to content

Instantly share code, notes, and snippets.

View leightkt's full-sized avatar

Kat Leight leightkt

View GitHub Profile
@leightkt
leightkt / shouter.html
Created July 25, 2018 19:26
JavaScript String Drills (wisePerson, shouter, textNormalizer)
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
</body>
@leightkt
leightkt / computeArea.html
Created July 25, 2018 19:30
Number Drills
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
</body>
@leightkt
leightkt / errorAlert.css
Created July 25, 2018 19:33
Logic Drills
* {
box-sizing: border-box;
}
main {
padding: 50px 20px;
}
.error-report {
color: red;
function accessFirstItem(array) {
return array[0];
}
function accessThirdItem(array) {
return array[2];
}
@leightkt
leightkt / average.js
Created July 30, 2018 01:22
Arrays and Loops Drills
// noprotect
// ^^ `noprotect` is here to prevent a bug with jsbin and for loops.
function average(numbers) {
numTotal = 0;
for (var i=0; i < numbers.length; i++) {
numTotal+= numbers[i];
}
return (numTotal)/numbers.length;
}
What is scope? Your explanation should include the idea of global vs. local scope.
Scope determines how you access variables created in JavaSctip. JavaScript has two types of scopes: global and local.
A variable created with global scope, known as a "Global," is accessible everywhere, even across files.
Every variable declared outside of a function in JavaSctip has global scope. A variable with local scope is only accessible
within the function block it was created in. It lives and dies within the function it was created in. When the function is finished,
the new variable disappears.
Why are global variables avoided?
Globals are avoided because they can create unintentional side effects and can make functions indeterminate. It can make things go wrong,
and then also be hard to debug. However, it is OK to use global variables when using a JavaScript Library like JQuery.
@leightkt
leightkt / deletingKeys.js
Created July 30, 2018 22:21
Object drills 1
function keyDeleter(obj) {
delete obj.foo;
delete obj.bar;
return obj;
}
var sampleObj = {
foo: 'foo',
bar: 'bar',
var studentData = [
{
name: 'Tim',
status: 'Current student',
course: 'Biology'
},
{
name: 'Sue',
status: 'Withdrawn',
course: 'Mathematics'
@leightkt
leightkt / mostFrequentWord.js
Created August 2, 2018 16:05
grokking exercise javascript
function getTokens(rawString) {
// NB: `.filter(Boolean)` removes any falsy items from an array
return rawString.toLowerCase().split(/[ ,!.";:-]+/).filter(Boolean).sort();
}
function mostFrequentWord(text) {
//pulling each word out of the array of text
var words = getTokens(text);
//creating and empty variable
var wordFrequencies = {};
@leightkt
leightkt / catCarousel.js
Created August 6, 2018 20:47
Event Listener Drills
// where I started. . .
// $(function(){
// $(".thumbnail").click(function(event) {
// $(".hero").replaceWith($(this));
// });
// });
// where I shifted, but couldn't figure out who to identify the src of the clicked image
// $(function(){
// $(".thumbnail").click(function(event) {