.filter is a method you can call on any array.
i.e. I want an array of all numbers greater than 10, I could:
const numbersGreaterThan10 = allNumbers.filter(num => num > 10)
Basic Reminders:
To create an array, use [] i.e. const allNumbers = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20]
For functions, && = and || = or
i.e. Display all the numbers that are either perfect squares or under 13 in #the perfect-squares-or-under-13 span
const oddNumbersPerfectorUnder13 = allNumbers.filter(
num => num < 13 || Math.sqrt(num) % 2 === 1)
Display all the odd perfect squares under 13 in the #odd-perfect-squares-under-13 span
const oddNumbersPerfectUnder13 = allNumbers.filter( num => num < 13 && Math.sqrt(num) % 2 === 1)
Objects: everything on the left is a “key”, and everything on the right is a “value” i.e [Key—>] Impossible Whopper: 1 [<—value]. This information can be extracted by using object.value(votes) (this will give you everything on the right of the ‘:’) or object.key(votes) (this will give you everything on the left of ‘:’
Adding the filters:HTML
First add to your HTML a div that will serve as your filter and search navigation, here called #number controls; don’t forget to add the drop down menu options the exact same way that the response is given i.e.
Using Chart.js:
1. Go to chatjs.org and click get started
2. Click on Chart JS CDN
3. Click on the `dist/.` folder and copy to clipboard the HTMl tag from the `dist/Chart.bundle.min.js`
4. Paste this HTML tag into your own HTML file
5. Create a new chart i.e.
New chart(“pie-chart”,{
type: ‘pie’,
data:{}
});
//We can use reference charts and data from chatjs.org
Functional example reference: https://repl.it/@andyweiss1982/TheVotesAreIn-1#script.js
Canvas is an html element that you use to draw pictures on the screen: `<canvas></canvas>`
DAY 10 Lesson
.filter
is a method you can call on any array. i.e. I want an array of all numbers greater than 10, I could: const numbersGreaterThan10 = allNumbers.filter(num => num > 10)Basic Reminders:
Display all the odd perfect squares under 13 in the #odd-perfect-squares-under-13 span
object.value(votes)
(this will give you everything on the right of the ‘:’) orobject.key(votes)
(this will give you everything on the left of ‘:’Adding the filters: HTML
JS
CSS
input, select { width: 100%; padding: 0.5rem; }
select { text-transform: capitalize; }
New chart(“pie-chart”,{ type: ‘pie’, data:{} });