Skip to content

Instantly share code, notes, and snippets.

View duggiemitchell's full-sized avatar
🏠
Working from home

Erica Edge duggiemitchell

🏠
Working from home
View GitHub Profile

The people at the Hoover Dam have called you back, and would like a program that shows what happens when only the even numbered turbines are turned on. And they want it all in just one for loop.

With a set of complex conditional statements inside the loop, construct a way to only turn on even numbered turbines. Remember our power output situation:

Generators 1 through 4 produce 62 MW. Generators 5 through 19 produce 124 MW. The output should follow this format:

Generator #1 is off. Generator #2 is on, adding 62 MW, for a total of 62 MW!

@duggiemitchell
duggiemitchell / ArrayArchipalaego.js
Created January 17, 2016 02:18
Two-Dimensional Arrays
Check out the following setup. Enter a line of code that declares a variable called infant and uses the array eightiesMovies to access the word "Baby".
var movie1 = [16, "Candles"];
var movie2 = [3, "Men", "and", "a", "Baby"];
var eightiesMovies = [movie1, movie2];
> var infant = eightiesMovies[4];
____
Now alert a string with the full title of the first movie in the eightiesMovies array, but only using the eightiesMovies variable to access the correct values. Use the concatenation operator to unite the words into one string, and remember to be attentive to necessary whitespace!
# Pig Latin
Translate the provided string to pig latin.
Pig Latin takes the first consonant (or consonant cluster) of an English word, moves it to the end of the word and suffixes an "ay".
If a word begins with a vowel you just add "way" to the end.
function translate(str) {
var RegEx = /[aeiouAEIOU]/;
var latinTranslation ="";
var vowelIndex ="";
if (str[0].match(RegEx)) {
@duggiemitchell
duggiemitchell / DNAPairs.js
Last active January 18, 2016 18:27
DNA Pairing
function pair(str) {
// Return each strand as an array of two elements, the original and the pair.
var paired = [];
// Function to check with strand to pair.
var search = function(char) {
switch (char) {
case 'A':
paired.push(['A', 'T']);
break;
@duggiemitchell
duggiemitchell / MappingArrays.js
Created January 19, 2016 00:03
Using Map With Arrays II
The passengers have arrived at Maple Mountain! Take the modifiedNames array that you produced in the last challenge, and map a new anonymous function on it.
The function should alert the following message to the screen for each passenger in turn:
var modifiedNames = [ "Thomas Meeks",
"Gregg Pollack",
"Christine Wong",
"Dan McGaw" ];
modifiedNames.map(function(modifiedNames) {
alert("Yo, " +modifiedNames+ "!");
@duggiemitchell
duggiemitchell / Closures.js
Last active January 20, 2016 15:07
Using a Closure II - CodeSchool JS Roadtrip Part 3
/*The Cove’s Dev Girls just got reports of icebergs in the area!
Build a warning message by passing a "iceberg" obstacle as an argument into the warningMaker function.
Store the results in a new variable called icebergAlert.
Call the icebergAlert function to view the warning message.*/
function warningMaker(obstacle) {
return function() {
alert("Beware! There have been " + obstacle + " sightings in the Cove today!");
};
@duggiemitchell
duggiemitchell / ObjectOcean.md
Last active January 27, 2016 14:59
What is Hard-Coding?

One thing I love about Codeschool is, the instructors place an emphasis on steering from hard coding in functions; a term I had not heard prior. So instead of using the real value when defining variables and/or functions, we use variables as a placeholder that we can reference later within the program. For an example, say we ar building a simple program calculating the area of a circle for a given radius. If we are hardcoding the program our function would look something like this:

 function areaOfCircle(radius) {
  return 2 * 3.14 * radius;
}
calculateCircumference(1); //returns 6.28

The formula to find the area of a circle is A = πr2. In the above function, the value 3.14 is hardcoded into our program when instead we could have used PI (since PI is not exactly 3.14, it is 3.14159 to be precise). Luckily, in Javascript there is such a property that represents the ratio of a circle's circumference: Math.PI ( Math.PI ≈ 3.14159 ). Imagine, if you will, that this value is used throughout our c

@duggiemitchell
duggiemitchell / lighthouse.js
Last active January 27, 2016 19:44
Object Creation & Manipulation - JS Roadtrip Part 4.2 - 4.9
//The ranger-devs want to upgrade Lighthouse Rock with new super-blinding light bulbs and remove the old existing bulbs. The new superBlinders array and lighthouseRock object are provided. Each index of the superBlinders array contains a bulb name and its wattage within a sub-array.
/*
Completely remove the existing bulbs property from the lighthouseRock object.
Add a weaponBulbs property to lighthouseRock and assign the superBlinders array as a value.
Log the name value of the bulb with the highest wattage to the console. Use the correct index from the weaponBulbs property of the lighthouseRock object to access the correct name value. */
var superBlinders = [
["Firelight", 4000],
["Solar Death Ray", 6000],
["Supernova", 12000]
];
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<script id="jsbin-javascript">
@duggiemitchell
duggiemitchell / es2015.md
Last active February 1, 2016 19:00
ES2016 Reference Sheet &Translations

Declarations

Using let Defines new variables scoped to the nearest block in which it has been declared, without affecting like-named variables outside of the block scope. Variables using let are not hoisted to the top They cannot be redeclared

//before:
var foo = 'bar';
//ES2015
let foo = 'bar';