This file contains 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
wisePerson: | |
function wisePerson(wiseType, whatToSay) { | |
let wiseQuote = "A wise ${wiseType} once said: \"${whatToSay}.\""; | |
return wiseQuote; | |
} | |
shouter: |
This file contains 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
wisePerson: | |
function wisePerson(wiseType, whatToSay) { | |
let wiseQuote = "A wise ${wiseType} once said: \"${whatToSay}.\""; | |
return wiseQuote; | |
} | |
shouter: |
This file contains 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 Area | |
function computeArea(width, height) { | |
const area = width * height; | |
return area; | |
} | |
Fahrenheit to Celsius and Celsius to Fahrenheit |
This file contains 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
Traffic lights drill | |
function doTrafficLights() { | |
const activeLight = getActiveLight(); | |
if (activeLight === "red"){ | |
turnRed(); | |
} | |
else if (activeLight === "yellow"){ | |
turnYellow(); | |
} |
This file contains 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
Make list drill | |
function makeList(item1, item2, item3) { | |
const arr = [item1, item2, item3]; | |
return arr; | |
} | |
Add to list drill |
This file contains 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
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; | |
} |
This file contains 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. 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. |
This file contains 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
Object creator: | |
function createMyObject() { | |
return myObject = { | |
foo: "bar", | |
answerToUniverse: 42, | |
"olly olly": "oxen free", | |
sayHello: function() { | |
return "hello" | |
} |
This file contains 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
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); | |
} | |
This file contains 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) { | |
//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); |
OlderNewer