Skip to content

Instantly share code, notes, and snippets.

View goldtreefrog's full-sized avatar

Margaret Blauvelt goldtreefrog

View GitHub Profile
'use strict';
function wisePerson(wiseType, whatToSay) {
return `A wise ${wiseType} once said: "${whatToSay}".`
}
console.log(wisePerson("goat","Hello world"));
function shouter(whatToShout) {
return whatToShout.toUpperCase() + "!!!";
'use strict';
function computeArea(width, height) {
return width * height;
}
let n1 = prompt("First number?");
let n2 = prompt("Second number?");
console.log("Area is " + computeArea(n1,n2));
https://repl.it/MuCe/1
https://repl.it/MuEC/1
@goldtreefrog
goldtreefrog / u2l4p2-arrays-basic-drills
Created October 19, 2017 15:48
Array Basic Drills
https://repl.it/MuMh - Create an array from parameters passed into a function. (u2l4p2-creating-arrays)
https://repl.it/MuOt - Add an item to the end of an array using "push". (u2l4p2-adding-arrays)
https://repl.it/MuQQ - Return first and third items from within an array. (u2l4p2-accessing-array-items)
https://repl.it/MuRi - Functions to 1) return length of array and 2) return last item of array. (u2l4p2-array-length-access)
@goldtreefrog
goldtreefrog / u2l4p4-array-method-drills
Created October 20, 2017 01:38
Array Method Drills
https://repl.it/MwHo - Copying portions of arrays using .slice(). (u2l4p4-array-copying-1)
https://repl.it/MwID/1 - More practice copying arrays. (u2l4p4-array-copying-2)
https://repl.it/MwJl - Squares in new array made using .map() method. (u2l4p4-squares-with-map)
https://repl.it/MwJ3 - Sort an array of numbers in reverse order. (u2l4p4-sort)
https://repl.it/MwJB - Filter an array according to word length. (u2l4p4-filter)
https://repl.it/MwJN - Find the first number in an array that is divisible by 5. (u2l4p4-find)
@goldtreefrog
goldtreefrog / u2l4p6-arrays-and-loops-drills
Last active October 20, 2017 06:39
Arrays and Loops Drills
https://repl.it/Mwca - Maximum and Minimum (u2l4p6-max-min.js)
https://repl.it/MwdS/0 - Average (u2l4p6-average.js)
https://repl.it/Mwd7/2 - Fizzbuzz (u2l4p6-fizzbuzz.js)
@goldtreefrog
goldtreefrog / u2l5p3-scope-and-globals
Created October 20, 2017 16:58
Scope and the Problem with Globals Q&A
What is scope? Your explanation should include the idea of global vs. local scope.
A: Scope refers to where a variable gets and retains its value and definition. A variable defined within a function only retains its definition and value within that function (and within subfunctions of that function). A variable defined globally is accessible and changeable everywhere, but if a variable with the same name is defined locally within a function, that local variable takes precedence while within that function - and disappears outside the function, while the global variable remains.
Why are global variables avoided?
A: Unexpected results are more likely to happen because a variable such a variable may be used by more than one function, and changing its value from within one function will change it for other functions as well. If that was not the intention, bugs will happen.
Explain JavaScript's strict mode
A: JavaScript's "use strict" statement causes JavaScript to issue an error any time a variable is not explic
@goldtreefrog
goldtreefrog / u2l6p2-object-drills-1
Last active October 22, 2017 05:01
Object Drills 1
https://repl.it/NBRi - Object Creator; create an object literal (u2l6p2-object-creator.js)
https://repl.it/NBSM - Object Updater; add keys to an existing object (u2l6p2-object-updater.js)
https://repl.it/NBST/1 - Self-Reference; reference variables within the same function using "this". (u2l6p2-self-reference.js)
https://repl.it/NBSF/2 - Deleting Keys (u2l6p2-deleting-keys.js)
@goldtreefrog
goldtreefrog / u2l6p5-object-drills-2
Last active October 23, 2017 02:15
Object Drills 2
https://repl.it/NCFD/1 - Create a function that takes an object and outputs an array ready for report (u2l6p5-make-student-reports.js)
https://repl.it/NCtc - Input an array to change students' status value, returning in another array. (u2l6p5-enroll-in-summer-school.js)
https://repl.it/NDCK - Given an array of objects and an ID number, find the one whose ID number matches. (u2l6p5-find-by-id.js)
https://repl.it/NDGt - Validate keys in object against expected keys. (u2l6p5-validate-object-keys.js)
@goldtreefrog
goldtreefrog / u2l6p6-analyze-frequent-word-program
Created October 23, 2017 19:02
Analysis of Frequent Word Program
The mostFrequentWords() function passes a string to the getTokens() function, which
splits it into an array of words, returning that to mostFrequentWords(), which saves
it into the "words" array. mostFrequentWords() then tabulates each word in the array,
storing the results in an object array called wordFrequencies, within which each
unique word is a key with a value corresponding to the number of times the word was
encountered in the
"words" array.
The function then loops through the wordFrequences array to find the word
with the highest number of occurrences, comparing each count to the highest