Skip to content

Instantly share code, notes, and snippets.

@camckin10
camckin10 / objectdrills2.js
Last active March 15, 2017 01:09
objectdrills2.js
1.)make student report
function makeStudentsReport(data) {//function name w/ argument
var answers = [];//create an empty array
for (var i=0; i<data.length; i++) {//for loop that measures length
var reports = data[i];//create another variable that has the argument
//inputting the for loop variable?
answers.length(reports.name + reports.grade);//ask the computer to
//print the length of the answers
}
return answers;//returning the array with proper information
@camckin10
camckin10 / drilsanswers.js
Last active February 21, 2017 02:24
Drills Answers
EXAMPLE PROBLEM W/MICHAEL
//var number_list = [1,3,6,6,7,8,2]
function problem(number_list){
//var number_list = [4,6,10,12]
var sum_counter = 0
for(var i = 0; i <number_list.length; i++) {
var value = number_list[i]
sum_counter = value + sum_counter
@camckin10
camckin10 / pedro-drills.js
Last active January 14, 2017 00:15
pedro-drills.js
//word counter drill
function wordCounter(word_list) {
}
// Should return { apple: 3, orange: 1 }
wordCounter(['apple', 'apple', 'apple', 'orange']);
function wordCounter(word_list){
var fruit = {};
@camckin10
camckin10 / advancedobjects-drills.js
Last active December 27, 2016 18:57
advancedobjects-drills.js
//most frequent word
function mostFrequentWord(words) {
var count = {
orange:1,
apple:3,
kiwi:2
var biggestWord = "";
var biggestCount=0;
object.jetys(count).forEach(
@camckin10
camckin10 / thinkful-notes.js
Last active February 4, 2017 02:53
thinkful notes
//thinkful notes with pedro dec.8.16
function mostFrequentWord(words) {
// count = {};
// count['apple'] = 1;
// count['apple'] = 3;
// count['apple'] = count['apple'] + 3;
// This would give me an object like:
// var count = {
// apple: 6
@camckin10
camckin10 / object-drills.js
Created December 7, 2016 02:34
Object basics drills
//object creator
function createMyObject () {
return {
foo: 'bar',
answerToUniverse:42,
'olly olly': 'oxen free',
sayHello: function () {
return ('hello');
}
}
@camckin10
camckin10 / scope-challenge
Last active December 5, 2016 15:49
Challenge: In Your Own Words
What is scope? Your explanation should include the idea of global vs. local scope.
With variables, there are two types: global and local. A global scope is a variable that is declared in the main body source of your code.
For example, imagine you have an JS file that has a variable declared *before* there is a function. Your global scope
would look like this: var schoolName="Island"; A local scope is a variable that has been declared and is *only* accessible through a set of
instructions, such a function. For example, if you were to have a JS file, and in this JS file there is a function called "mySchool."
Then your local scope in your JS file would look like this: function mySchool()
var schoolNames="Island";
Why are global variables avoided?
Global variables are avoided because they can make your code extremely messy. Global variable or scope that is declared can be available