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
var testOneMessage = "test failing"; | |
function testOne(testOneMessage) {//every param becomes a new var local | |
// Test One Restrictions: Do not declare any new variable with the var keyword | |
// Do not reassign testOneMessage | |
console.log("Test one: ", testOneMessage); | |
} | |
// Run test one | |
testOne("test succeeding"); |
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
var badGuys = function() { | |
var bond = '007'; | |
//does not get redefined and does know what bond is and its value | |
(function oddJob() { | |
var AgentinScope = (bond === '007'); //true | |
var prediction = 'Bond stays the same because it already exists and does not get redefined'; | |
console.log("Bond in OddJob's scope", AgentinScope, "because " + prediction); | |
})(); |
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
var counter = 0; | |
function increment(num){ | |
counter += num; | |
console.log("counter: " + counter); | |
} | |
increment(2); // counter is now 2 | |
increment(6); // counter is now 8 | |
increment(-1); // counter is now 7 |
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
var puzzle = [[ 8,9,5, 7,4,2, 1,3,6 ], | |
[ 2,7,1, 9,6,3, 4,8,5 ], | |
[ 4,6,3, 5,8,1, 7,9,2 ], | |
[ 9,3,4, 6,1,7, 2,5,8 ], | |
[ 5,1,7, 2,3,8, 9,6,4 ], | |
[ 6,8,2, 4,5,9, 3,7,1 ], | |
[ 1,5,9, 8,7,4, 6,2,3 ], | |
[ 7,4,6, 3,2,5, 8,1,9 ], |
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 finderFunction(searchArray, testerFunction){ | |
for(var i=0;i<searchArray.length;i++){ | |
if(testerFunction(searchArray[i])){ | |
return i; | |
} | |
} | |
return -1; | |
} | |
function finderFunctionArray(searchArray, testerFunction){ |
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 biller(state){ | |
debugger; | |
if(state==="NY"){console.log("ny"); | |
var newYorkBiller=function(cost){ | |
var finalCost=((cost*1.03)*1.09).toFixed(2); | |
console.log(finalCost); | |
}; | |
return newYorkBiller; | |
}else{console.log("nj"); | |
var newJersBiller=function(cost){ |
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 functionLogger(myFunc, myFuncParam){ | |
myFunc(myFuncParam); | |
} | |
function sayHello(person){ | |
console.log("Hello " + person +"!"); | |
} | |
function sayGoodbye(person){ | |
console.log("Bye " + person +"!"); | |
} | |
functionLogger(sayGoodbye, "Patrick"); |
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 mean(score1, score2, score3){ | |
var totalScore=0; | |
totalScore+=score1; | |
totalScore+=score2; | |
totalScore+=score3; | |
var totalMean=totalScore/3; | |
return totalMean; | |
} |
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 longDate(myDate){ | |
var monthArray = ["", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]; | |
var dateArray = myDate.split("/"); | |
var month = monthArray[dateArray[0]]; | |
var day = dateArray[1]; | |
var year = dateArray[2]; | |
if(year.length === 2){ | |
if(year <= "20"){ | |
year = "20" + year; |
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 exponentiate(num1, num2){ | |
var output=1; | |
for(var i=0;i<num2;i++){ | |
output*=num1;console.log(i," ",output); | |
} | |
return output; | |
} | |
exponentiate(2, 2) // => 4 | |
//exponentiate(3, 4) // => 81 |