Skip to content

Instantly share code, notes, and snippets.

function handleThumbnailClicks() {
$('.thumbnail').click(function(event) {
var imgSrc = $(event.currentTarget).find('img').attr('src');
$('.hero img').attr('src', imgSrc);
})
}
$(function() {
handleThumbnailClicks();
});
@michelleroth
michelleroth / index.html
Created December 15, 2016 02:58 — forked from tbywong/index.html
Framework Day 10 Exercise
<!DOCTYPE html>
<html>
<head>
<title>Class 10 - Framework</title>
</head>
<body>
<h1>AJAX DOM Manipulation</h1>
<div class="users">
<h3>Users: </h3>
function mostFrequentWord(words) {
var wordFrequencies = {};
for (var i = 0; i <= words.length; i++) {
if (words[i] in wordFrequencies) {
wordFrequencies[words[i]]++;
}
else {
wordFrequencies[words[i]]=1;
}
}
function createMyObject() {
return {
foo: 'bar',
answerToUniverse: 42,
'olly olly': 'oxen free',
sayHello: function() {
return 'hello';
}
};
}
JS has two scopes which can be defined as a region of the program; local and global. A variable declared outside of a function becomes part of the global scope, but if it is declared within the function it is encompassed by the local scope. By declaring a variable a part of the global scope, you are making it vulnerable to error and bugs, as it is accessible to from any code within the program you are modifying.
As mentioned above, global variables create more opportunity for errors and problems as it is accessible from anywhere within the program and can cause unforeseen large scale problems if something goes wrong and the wrong functions or variables are affected.
Strict mode is a safe guard, and it is designed to warn you if you are sending something into the global scope. It is written initially as a rule before the syntax is written and is commonly used.
Side effects are accidental issues caused primarily with global scope. Everything that is not a planned return but ends up causing problems for
function max(numbers) {
var currentMax = numbers[0];
for (var i=0; i <= numbers.length; i++) {
if (numbers[i] > currentMax) {
currentMax = numbers[i];
}
}
return currentMax;
}
function doTrafficLights() {
turnOffLights();
var activeLight = getActiveLight();
if (activeLight === 'red') {
turnRed();
}
if (activeLight === 'yellow') {
turnYellow();
}
if (activeLight === 'green') {
function isDivisible(divisee, divisor) {
return divisee % divisor === 0;
}
/* From here down, you are not expected to
understand.... for now :)
Nothing to see here!
function wisePerson(wiseType, whatToSay) {
return 'A wise ' +
wiseType + ' once said: "' + whatToSay + '".';
}
/* From here down, you are not expected to
understand.... for now :)