Skip to content

Instantly share code, notes, and snippets.

View schamblee's full-sized avatar

Stephanie Chamblee schamblee

  • Lexington, Kentucky
View GitHub Profile
function textNormalizer(text) {
return `${text.toLowerCase().trim()}`
}
function shouter(whatToShout) {
return `${whatToShout.toUpperCase()}!!!`;
}
function wisePerson(wiseType, whatToSay) {
return `A wise ${wiseType} once said: "${whatToSay}".`;
function computeArea(width, height) {
return width * height;
}
function celsToFahr(celsTemp) {
return celsTemp * 1.8 + 32;
}
function fahrToCels(fahrTemp) {
return (fahrTemp - 32) * 1.8;
function doTrafficLights() {
const activeLight = getActiveLight();
if (activeLight === 'red') {
turnRed()
} else if (activeLight ==="green") {
turnGreen()
} else {
turnYellow()
}
}
Creating arrays
function makeList(item1, item2, item3) {
return [item1, item2, item3]
}
Adding array items
function addToList(list, item) {
list.push(item);
Array copying I
function firstFourItems(array) {
return array.slice(0, 4)
}
function lastThreeItems(array) {
return array.slice(-3)
}
max and min (without sort)
function max(numbers) {
maxNumber = numbers[0];
for (let i = 0; i < numbers.length; i++) {
if (maxNumber < numbers[i]) {
maxNumber = numbers[i];
}
}
return maxNumber
What is scope? Your explanation should include the idea of global vs. local scope.
Scope refers to the boundaries in which a variable or constant will interact with functions in code.
A variable has global scope when it is defined outside of a function. Global variables will be recognized
by functions throughout a folder of JS files.
A variable has local scope when it is defined within a function. A local variable is only recognized
within its function.
Why are global variables avoided?
As an app becomes more complex and requires many functions, global variables can cause there to be bugs
which are difficult to find. For example, if a global variable is defined in one JS file and altered in a function in another JS File in another,
Object creator
function createMyObject(key1, key2, key3, key4) {
obj = {
foo: 'bar',
answerToUniverse: 42,
'olly olly': 'oxen free',
sayHello: function sayHello() {
return `hello`
}
Make student reports: https://repl.it/@Stephaniejoy/Make-student-reports-drill
Enroll in summer school: https://repl.it/@Stephaniejoy/Enroll-in-summer-school-drill
Find by id: https://repl.it/@Stephaniejoy/find-by-id-drill
Validate object keys: https://repl.it/@Stephaniejoy/validate-object-keys-drill
Commented code: https://repl.it/@Stephaniejoy/most-frequent-word-analyzer-challenge