Skip to content

Instantly share code, notes, and snippets.

wisePerson:
function wisePerson(wiseType, whatToSay) {
let wiseQuote = "A wise ${wiseType} once said: \"${whatToSay}.\"";
return wiseQuote;
}
shouter:
wisePerson:
function wisePerson(wiseType, whatToSay) {
let wiseQuote = "A wise ${wiseType} once said: \"${whatToSay}.\"";
return wiseQuote;
}
shouter:
@gusmcnair
gusmcnair / Thinkful numbers assignment
Created October 1, 2019 18:32
Thinkful numbers assignment
Compute Area
function computeArea(width, height) {
const area = width * height;
return area;
}
Fahrenheit to Celsius and Celsius to Fahrenheit
@gusmcnair
gusmcnair / Application logic drills
Created October 1, 2019 19:11
Application logic drills
Traffic lights drill
function doTrafficLights() {
const activeLight = getActiveLight();
if (activeLight === "red"){
turnRed();
}
else if (activeLight === "yellow"){
turnYellow();
}
Make list drill
function makeList(item1, item2, item3) {
const arr = [item1, item2, item3];
return arr;
}
Add to list drill
@gusmcnair
gusmcnair / Loops and arrays solutions
Created October 1, 2019 22:48
Loops and arrays solutions
Max and min
function max(numbers) {
let maximum = numbers[0]
for(i = 0; i < numbers.length; i++){
if (numbers[i] > maximum){
maximum = numbers[i]
}
} return maximum;
}
@gusmcnair
gusmcnair / Variable scope questions and answers
Created October 2, 2019 17:58
Variable scope questions and answers
What is scope? Your explanation should include the idea of global vs. block scope.
Scope describes where and when a variable can be accessed in code.
Global scope is available anywhere in the code, whereas block is only available in a specific function or situation.
Why are global variables avoided?
Global variables can cause functions to be indeterminate, which means that they can have the same input and produce different results.
They can also cause code to behave in unexpected ways and make debugging difficult.
@gusmcnair
gusmcnair / Object basics assignment
Created October 2, 2019 18:31
Object basics assignment
Object creator:
function createMyObject() {
return myObject = {
foo: "bar",
answerToUniverse: 42,
"olly olly": "oxen free",
sayHello: function() {
return "hello"
}
@gusmcnair
gusmcnair / Iterating Through Objects problems
Created October 2, 2019 23:01
Iterating Through Objects problems
Make Students Report
function makeStudentsReport(data) {
let students = [];
for (i = 0; i < data.length; i++){
students.push(`${data[i].name}: ${data[i].grade}`)
} return(students);
}
@gusmcnair
gusmcnair / Grokking assignment: Most frequent word
Created October 3, 2019 01:47
Grokking assignment: Most frequent word
function getTokens(rawString) {
//This section splits words into strings by splitting at spaces and punctuation, makes them all lowercase so upper/lowercase letters will be counted as the same, and removes all non-truthy values.
return rawString.toLowerCase().split(/[ ,!.";:-]+/).filter(Boolean)
//This sorts the elements alphabetically
.sort();
}
function mostFrequentWord(text) {
//Runs the above function getTokens and identifies the results as the variable "words"
let words = getTokens(text);