Skip to content

Instantly share code, notes, and snippets.

View iancover's full-sized avatar
💻

Ian Cover iancover

💻
View GitHub Profile
@iancover
iancover / InYourOwnWords.txt
Last active January 18, 2022 11:57
Thinkful JS Q&A
What is scope? Your explanation should include the idea of global vs. local scope.
SCOPE IS THE UMBRELLA OR ROOM WHERE THE JS INTERPRETER IS LOOKING FOR VARIABLES TO USE, THESE COULD BE
IN THE GLOBAL SCOPE WHICH COULD BE THE UMBRELLA FOR MANY FUNCTIONS IN MANY FILES OR IT COULD BE LOCAL,
WHICH WOULD BE IN JUST A BLOCK OF INSTRUCTIONS FOR ONE FUNCTION
Why are global variables avoided?
THEY CAN BE HARD TO TRACK IF THERE'S ALOT OF SCRIPT TO SEARCH ON AND COULD CAUSE BUGS
// Compute Average Drill
function average(numbers) {
var avg = numbers.reduce(function sum(total,num) {
return total + num;
})
return avg/numbers.length;
}
// I used the .reduce() method with .length
@iancover
iancover / arrayEvery.js
Last active January 18, 2022 12:16
Thinkful JS Arrays exercises
// Array Ex 6
function makeList(item1, item2, item3) {
return [item1,item2,item3];
}
// tests
function testMakeList() {
var items = ["prime rib", "fried goat cheese salad", "fish tacos"];
var result = makeList(items[0], items[1], items[2]);
@iancover
iancover / errorAlert.js
Last active January 18, 2022 11:55
Thinkful jQuery exercises
// jQuery example
function main() {
try {
doAllTheThings();
}
catch(e) {
console.error(e);
reportError(e);
}
@iancover
iancover / computeArea.js
Last active January 18, 2022 11:51
Thinkful exercises: JS functions using numbers
function computeArea(width, height) {
return width*height
}
function testComputeArea() {
var width = 3;
var height = 4;
var expected = 12;
if (computeArea(width, height) === expected) {
console.log('SUCCESS: `computeArea` is working');
@iancover
iancover / shouter.js
Last active January 18, 2022 11:46
Thinkful exercises: JS functions using strings
function shouter(whatToShout) {
return whatToShout.toUpperCase () + '!!!'
}
function testShouter() {
var whatToShout = 'as you can hear i am whispering';
var expected = 'AS YOU CAN HEAR I AM WHISPERING!!!';
if (shouter(whatToShout) === expected) {
console.log('SUCCESS: `shouter` is working');
}