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 wisePerson(wiseType, whatToSay) { | |
return 'A wise ' + | |
wiseType + ' once said: "' + whatToSay + '".'; | |
} | |
/* From here down, you are not expected to | |
understand.... for now :) | |
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 isDivisible(divisee, divisor) { | |
return divisee % divisor === 0; | |
} | |
/* From here down, you are not expected to | |
understand.... for now :) | |
Nothing to see here! |
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 doTrafficLights() { | |
turnOffLights(); | |
var activeLight = getActiveLight(); | |
if (activeLight === 'red') { | |
turnRed(); | |
} | |
if (activeLight === 'yellow') { | |
turnYellow(); | |
} | |
if (activeLight === 'green') { |
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 max(numbers) { | |
var currentMax = numbers[0]; | |
for (var i=0; i <= numbers.length; i++) { | |
if (numbers[i] > currentMax) { | |
currentMax = numbers[i]; | |
} | |
} | |
return currentMax; | |
} |
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
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 |
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 createMyObject() { | |
return { | |
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
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; | |
} | |
} |
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Class 10 - Framework</title> | |
</head> | |
<body> | |
<h1>AJAX DOM Manipulation</h1> | |
<div class="users"> | |
<h3>Users: </h3> |
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 handleThumbnailClicks() { | |
$('.thumbnail').click(function(event) { | |
var imgSrc = $(event.currentTarget).find('img').attr('src'); | |
$('.hero img').attr('src', imgSrc); | |
}) | |
} | |
$(function() { | |
handleThumbnailClicks(); | |
}); |
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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<title>my game</title> | |
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/4.2.0/normalize.min.css"> | |
<link href="https://fonts.googleapis.com/css?family=Roboto" rel="stylesheet"> | |
<link rel="stylesheet" href="main.css"> | |
</head> |
OlderNewer