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
hardness_scale = {"talc": 1, "gypsum": 3, "calcite": 9} | |
minerals = {} | |
for a_key in hardness_scale.keys(): | |
minerals[a_key] = hardness_scale[a_key] | |
print(minerals) #{'talc': 1, 'gypsum': 3, 'calcite': 9} | |
for a_key in hardness_scale: | |
minerals[a_key] = hardness_scale[a_key] | |
print(minerals) #{'talc': 1, 'gypsum': 3, 'calcite': 9} |
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
d1 = {"a":1, "b":2, "c":3} | |
d2 = {"x":4, "y":5, "z":6} | |
for key in d1: | |
d2[key] = d1[key] | |
# print(d2) | |
#{'x': 4, 'y': 5, 'z': 6, 'a': 1, 'b': 2, 'c': 3} |
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
//Object creator | |
function createMyObject() { | |
return { | |
foo: "bar", | |
answerToUniverse: 42, | |
"olly olly": "oxen free", | |
sayHello: function() { | |
return "hello"; | |
} |
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 namespace of a data element. Global scope encompasses the entire code project; global values can be called anywhere within the project. Local scope is contained with a particular function; other functions cannot access those values. It also means that functions within functions cannot be accessed outside the containing function. | |
Why are global variables avoided? | |
Global variables can overstep their bounds and cause unintended side effects if they are manipulated in a way that wasn't planned for. For example, if a developer has a global variable and a local variable with the same name, she may forget that fact and call the global variable instead of the local variable, changing the global value and ultimately changing the result of the program. | |
Explain JavaScript's strict mode |
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
//Min-max | |
function max(numbers) { | |
var high = numbers[0]; | |
for (var i = 0; i <= numbers.length; i++) { | |
if (numbers[i] > high) { | |
high = numbers[i]; | |
} | |
} | |
return high; | |
} |
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
//Make List | |
function makeList(item1, item2, item3) { | |
return list = [item1, item2, item3]; | |
} | |
//Add to array | |
function addToList(list, item) { | |
var list = list; | |
list.push(item); | |
return list; |
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
//Traffic Light | |
function doTrafficLights() { | |
var activeLight = getActiveLight(); | |
if (activeLight === "red"){ | |
turnRed();} | |
else if (activeLight === "yellow"){ | |
turnYellow();} | |
else if (activeLight === "green"){ | |
turnGreen();} |
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
//Area | |
function computeArea(width, height) { | |
return width * height; | |
} | |
//Temp conversion | |
function celsToFahr(celsTemp) { | |
return (celsTemp * 9)/5 + 32; | |
} |
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
//WisePerson generator | |
function wisePerson(wiseType, whatToSay) { | |
return ("A wise " + wiseType + " once said: \"" + | |
whatToSay + "\"."); | |
console.log(phrase); | |
} | |
//Shouter | |
function shouter(whatToShout) { | |
return whatToShout.toUpperCase() + "!!!"; |
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
1) What is the 1994 rate of juvenile delinquency in the U.S.? Good | |
2) What can we do to reduce juvenile delinquency in the U.S.? Bad | |
a) What has been done to address juvenile delinquency? | |
b) What are the most effective ways to reduce delinquency? | |
3) Does education play a role in reducing juvenile delinquents' return to crime? Good | |
4) How many customers does AT&T currently serve in Washington, DC? Good | |
5) What factors lead consumers to choose AT&T over other service providers? Good | |
6) How can AT&T attract more customers? Bad | |
a) For a given scenario, does the number of customers increase? | |
7) Why did the Challenger Shuttle explode? Bad |
NewerOlder