Skip to content

Instantly share code, notes, and snippets.

@joncancode
joncancode / shouter
Created May 19, 2017 17:24
wisePerson drill
function shouter(whatToShout) {
return whatToShout.toUpperCase() + "!!!";
}
/* From here down, you are not expected to
understand.... for now :)
Nothing to see here!
@joncancode
joncancode / computeArea
Created May 19, 2017 17:48
number drills
function computeArea(width, height) {
return width * height
}
/* From here down, you are not expected to
understand.... for now :)
Nothing to see here!
@joncancode
joncancode / traffic
Created May 20, 2017 15:31
Logic Drills
function doTrafficLights() {
turnOffLights();
var activeLight = getActiveLight();
if (activeLight === 'red') {
turnRed();
}
if (activeLight === 'yellow') {
turnYellow();
}
if (activeLight === 'green') {
function accessFirstItem(array) {
return array[0]
}
function accessThirdItem(array) {
return array[2]
}
@joncancode
joncancode / average
Created May 21, 2017 02:19
arrays and loop drills
function average(numbers) {
var total = numbers[0];
for (var i=1; i < numbers.length; i++) {
total+= numbers[i];
}
return total/numbers.length;
}
/* From here down, you are not expected to
understand.... for now :)
@joncancode
joncancode / Scope questions
Created May 22, 2017 19:38
Scope assignment in my own words
What is scope? Your explanation should include the idea of global vs. local scope.
The scope is what you are able to access within a group of code. Global scope refers to variables that are accessible everywhere, while the local scope is more specific. For example, if a variable is defined within a function, it is local to that function and no where outside of it. However, if a variable is defined outside of this function, it is global and you are able to access it in multiple functions.
Why are global variables avoided?
Global variables make unintended side effects in a program more likely, meaning it will be harder to track down bugs in your code. There is just one global scope as opposed to the many local scopes that can be created (and bugs that can avoided from these multiple scopes).
Explain JavaScript's strict mode
@joncancode
joncancode / deleting keys
Created May 23, 2017 05:27
object drills
function keyDeleter(obj) {
delete obj.foo;
delete obj.bar;
return obj;
}
var sampleObj = {
foo: 'foo',
bar: 'bar',
var studentData = [
{
name: 'Tim',
status: 'Current student',
course: 'Biology'
},
{
name: 'Sue',
status: 'Withdrawn',
course: 'Mathematics'
@joncancode
joncancode / word frequency
Created May 24, 2017 22:18
challenge: word frequency exercise
function getTokens(rawString) {
// NB: `.filter(Boolean)` removes any falsy items from an array
return rawString.toLowerCase().split(/[ ,!.";:-]+/).filter(Boolean).sort();
}
function mostFrequentWord(text) {
//this is saying we will use a function called mostFrequentWord that will have text as its only parameter
var words = getTokens(text);
//now we are making a variable called words that will basically be the getTokens function
@joncancode
joncancode / bulb
Created May 30, 2017 03:16
event listener
function handleBulbClicks() {
$('.lightbulb').click(function(event){
$('.lightbulb').removeClass('bulb-on')
$(event.currentTarget).addClass('bulb-on')
});
}
$(function() {
handleBulbClicks();
});