This file contains hidden or 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
| 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 |
This file contains hidden or 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
| 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 |
This file contains hidden or 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
| //word counter drill | |
| function wordCounter(word_list) { | |
| } | |
| // Should return { apple: 3, orange: 1 } | |
| wordCounter(['apple', 'apple', 'apple', 'orange']); | |
| function wordCounter(word_list){ | |
| var fruit = {}; |
This file contains hidden or 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
| //most frequent word | |
| function mostFrequentWord(words) { | |
| var count = { | |
| orange:1, | |
| apple:3, | |
| kiwi:2 | |
| var biggestWord = ""; | |
| var biggestCount=0; | |
| object.jetys(count).forEach( |
This file contains hidden or 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
| //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 |
This file contains hidden or 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
| //object creator | |
| function createMyObject () { | |
| return { | |
| foo: 'bar', | |
| answerToUniverse:42, | |
| 'olly olly': 'oxen free', | |
| sayHello: function () { | |
| return ('hello'); | |
| } | |
| } |
This file contains hidden or 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
| 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 |
NewerOlder