This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// jQuery example | |
function main() { | |
try { | |
doAllTheThings(); | |
} | |
catch(e) { | |
console.error(e); | |
reportError(e); | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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]); | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Create My Object Drill | |
// Write a function that returns an object with key/value pairs: foo=>bar, answerToUniverse=>42, olly olly=>oxen, and | |
// sayHello=> function that returns the string 'hello' | |
function createMyObject() { | |
return myObject = { | |
foo: 'bar', | |
answerToUniverse: 42, | |
'olly olly': 'oxen free', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Write a function called enrollInSummerSchool that takes a single argument, students. | |
// students is an array of objects, with each object representing a student — | |
// for example, {name: 'Tim', status: 'Current student', course: 'Biology'}. | |
// enrollInSummerSchool should return an array of objects. | |
// For each object from the original array, it should return the original name and course, | |
// but should update the status to In Summer school. | |
function enrollInSummerSchool(students) { | |
var results = []; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var obj1 = { | |
key1: 1, | |
key2: 'Value2', | |
key3: 3, | |
key4: 'Value4' | |
} | |
var obj2 = { | |
key1: 1, | |
key2: 'Value2', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getTokens(rawString) { | |
// NB: `.filter(Boolean)` removes any falsy items from an array | |
// method '.toLowerCase' makes all the characters in the string 'rawString' smallcaps | |
// method '.split' splits each item in the string with the characters passed | |
// method '.sort()' will sort the string alphabetically | |
return rawString.toLowerCase().split(/[ ,!.";:-]+/).filter(Boolean).sort(); | |
} | |
function mostFrequentWord(text) { | |
// locally creating a variable 'words' that calls the function getTokens passing the argument on this function |
OlderNewer