Skip to content

Commit 2c39fd1

Browse files
authored
Merge pull request #1 from emodo/dev
self
2 parents e2c623f + f5c1946 commit 2c39fd1

File tree

21 files changed

+1716
-0
lines changed

21 files changed

+1716
-0
lines changed
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>JS Drum Kit</title>
6+
<link rel="stylesheet" href="style.css">
7+
</head>
8+
<body>
9+
10+
11+
<div class="keys">
12+
<div data-key="65" class="key">
13+
<kbd>A</kbd>
14+
<span class="sound">clap</span>
15+
</div>
16+
<div data-key="83" class="key">
17+
<kbd>S</kbd>
18+
<span class="sound">hihat</span>
19+
</div>
20+
<div data-key="68" class="key">
21+
<kbd>D</kbd>
22+
<span class="sound">kick</span>
23+
</div>
24+
<div data-key="70" class="key">
25+
<kbd>F</kbd>
26+
<span class="sound">openhat</span>
27+
</div>
28+
<div data-key="71" class="key">
29+
<kbd>G</kbd>
30+
<span class="sound">boom</span>
31+
</div>
32+
<div data-key="72" class="key">
33+
<kbd>H</kbd>
34+
<span class="sound">ride</span>
35+
</div>
36+
<div data-key="74" class="key">
37+
<kbd>J</kbd>
38+
<span class="sound">snare</span>
39+
</div>
40+
<div data-key="75" class="key">
41+
<kbd>K</kbd>
42+
<span class="sound">tom</span>
43+
</div>
44+
<div data-key="76" class="key">
45+
<kbd>L</kbd>
46+
<span class="sound">tink</span>
47+
</div>
48+
</div>
49+
50+
<audio data-key="65" src="sounds/clap.wav"></audio>
51+
<audio data-key="83" src="sounds/hihat.wav"></audio>
52+
<audio data-key="68" src="sounds/kick.wav"></audio>
53+
<audio data-key="70" src="sounds/openhat.wav"></audio>
54+
<audio data-key="71" src="sounds/boom.wav"></audio>
55+
<audio data-key="72" src="sounds/ride.wav"></audio>
56+
<audio data-key="74" src="sounds/snare.wav"></audio>
57+
<audio data-key="75" src="sounds/tom.wav"></audio>
58+
<audio data-key="76" src="sounds/tink.wav"></audio>
59+
60+
<script>
61+
const keys = document.querySelectorAll('.key');
62+
63+
document.addEventListener('keydown', keydown, false);
64+
65+
function keydown(e) {
66+
const audio = document.querySelector(`audio[data-key="${e.keyCode}"]`);
67+
const key = document.querySelector(`.key[data-key="${e.keyCode}"]`);
68+
if (!audio || e.repeat) {
69+
return;
70+
}
71+
72+
key.classList.add('playing');
73+
audio.currentTime = 0;
74+
audio.play();
75+
}
76+
77+
function removeTransition(e) {
78+
if (e.propertyName !== 'transform') {
79+
return;
80+
}
81+
82+
this.classList.remove('playing');
83+
}
84+
85+
keys.forEach(key => key.addEventListener('transitionend', removeTransition));
86+
</script>
87+
88+
89+
</body>
90+
</html>

02 - JS and CSS Clock/index-SELF.html

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>JS + CSS Clock</title>
6+
</head>
7+
<body>
8+
9+
10+
<div class="clock">
11+
<div class="clock-face">
12+
<div class="hand hour-hand"></div>
13+
<div class="hand min-hand"></div>
14+
<div class="hand second-hand"></div>
15+
</div>
16+
</div>
17+
18+
19+
<style>
20+
html {
21+
background:#018DED;
22+
background-size:cover;
23+
font-family:'helvetica neue';
24+
text-align: center;
25+
font-size: 10px;
26+
}
27+
28+
body {
29+
margin: 0;
30+
font-size: 2rem;
31+
display:flex;
32+
flex:1;
33+
min-height: 100vh;
34+
align-items: center;
35+
}
36+
37+
.clock {
38+
width: 30rem;
39+
height: 30rem;
40+
border:20px solid white;
41+
border-radius:50%;
42+
margin:50px auto;
43+
position: relative;
44+
padding:2rem;
45+
box-shadow:
46+
0 0 0 4px rgba(0,0,0,0.1),
47+
inset 0 0 0 3px #EFEFEF,
48+
inset 0 0 10px black,
49+
0 0 10px rgba(0,0,0,0.2);
50+
}
51+
52+
.clock-face {
53+
position: relative;
54+
width: 100%;
55+
height: 100%;
56+
transform: translate(-3px, -3px); /* account for the height of the clock hands */
57+
}
58+
59+
.hand {
60+
width:50%;
61+
height:6px;
62+
background: #d50000;
63+
position: absolute;
64+
top: 50%;
65+
left: 50%;
66+
transform-origin: 0;
67+
transform: rotate(-90deg);
68+
transition: all .3s;
69+
}
70+
71+
.hour-hand {
72+
width: 40%;
73+
background: #ff6d00;
74+
}
75+
76+
.min-hand {
77+
width: 48%;
78+
background: #00bfa5;
79+
}
80+
</style>
81+
82+
<script>
83+
var transformProp = (function(){
84+
var testEl = document.createElement('div');
85+
if(testEl.style.transform == null) {
86+
var vendors = ['Webkit', 'Moz', 'ms'];
87+
for(var vendor in vendors) {
88+
if(testEl.style[ vendors[vendor] + 'Transform' ] !== undefined) {
89+
return vendors[vendor] + 'Transform';
90+
}
91+
}
92+
}
93+
return 'transform';
94+
})();
95+
96+
setInterval(clock, 1000);
97+
98+
function clock() {
99+
const now = new Date();
100+
const minutes =
101+
document.querySelector('.second-hand').style[transformProp] = `rotate(${now.getSeconds() / 60 * 360 - 90}deg)`;
102+
document.querySelector('.min-hand').style[transformProp] = `rotate(${(now.getMinutes() / 60 * 360) + now.getSeconds() / 60 * 6 - 90}deg)`;
103+
document.querySelector('.hour-hand').style[transformProp] = `rotate(${(now.getHours() / 12 * 360) + now.getMinutes() / 60 * 30 - 90}deg)`;
104+
}
105+
106+
</script>
107+
</body>
108+
</html>

03 - CSS Variables/index-SELF.html

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>Scoped CSS Variables and JS</title>
6+
</head>
7+
<body>
8+
<h2>Update CSS Variables with <span class='hl'>JS</span></h2>
9+
10+
<div class="controls">
11+
<label for="spacing">Spacing:</label>
12+
<input id="spacing" type="range" name="spacing" min="10" max="200" value="10" data-sizing="px">
13+
14+
<label for="blur">Blur:</label>
15+
<input id="blur" type="range" name="blur" min="0" max="25" value="10" data-sizing="px">
16+
17+
<label for="base">Base Color</label>
18+
<input id="base" type="color" name="base" value="#ffc600">
19+
</div>
20+
21+
<img src="https://source.unsplash.com/7bwQXzbF6KE/800x500">
22+
23+
<style>
24+
:root {
25+
--base: #ffc600;
26+
--spacing: 10px;
27+
--blur: 10px;
28+
}
29+
30+
img {
31+
padding: var(--spacing);
32+
filter: blur(var(--blur));
33+
background: var(--base);
34+
}
35+
36+
.hl {
37+
color: var(--base);
38+
}
39+
/*
40+
misc styles, nothing to do with CSS variables
41+
*/
42+
43+
body {
44+
text-align: center;
45+
}
46+
47+
body {
48+
background: #193549;
49+
color: white;
50+
font-family: 'helvetica neue', sans-serif;
51+
font-weight: 100;
52+
font-size: 50px;
53+
}
54+
55+
.controls {
56+
margin-bottom: 50px;
57+
}
58+
59+
input {
60+
width:100px;
61+
}
62+
</style>
63+
64+
<script>
65+
const inputs = document.querySelectorAll('.controls input');
66+
inputs.forEach(input => input.addEventListener('input', onChange));
67+
function onChange(e) {
68+
const suffix = this.dataset.sizing || '';
69+
document.documentElement.style.setProperty(`--${this.name}`, this.value + suffix);
70+
}
71+
</script>
72+
73+
</body>
74+
</html>
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>Array Cardio 💪</title>
6+
</head>
7+
<body>
8+
<p><em>Psst: have a look at the JavaScript Console</em> 💁</p>
9+
<script>
10+
// Get your shorts on - this is an array workout!
11+
// ## Array Cardio Day 1
12+
13+
// Some data we can work with
14+
15+
const inventors = [
16+
{ first: 'Albert', last: 'Einstein', year: 1879, passed: 1955 },
17+
{ first: 'Isaac', last: 'Newton', year: 1643, passed: 1727 },
18+
{ first: 'Galileo', last: 'Galilei', year: 1564, passed: 1642 },
19+
{ first: 'Marie', last: 'Curie', year: 1867, passed: 1934 },
20+
{ first: 'Johannes', last: 'Kepler', year: 1571, passed: 1630 },
21+
{ first: 'Nicolaus', last: 'Copernicus', year: 1473, passed: 1543 },
22+
{ first: 'Max', last: 'Planck', year: 1858, passed: 1947 },
23+
{ first: 'Katherine', last: 'Blodgett', year: 1898, passed: 1979 },
24+
{ first: 'Ada', last: 'Lovelace', year: 1815, passed: 1852 },
25+
{ first: 'Sarah E.', last: 'Goode', year: 1855, passed: 1905 },
26+
{ first: 'Lise', last: 'Meitner', year: 1878, passed: 1968 },
27+
{ first: 'Hanna', last: 'Hammarström', year: 1829, passed: 1909 }
28+
];
29+
30+
const people = ['Beck, Glenn', 'Becker, Carl', 'Beckett, Samuel', 'Beddoes, Mick', 'Beecher, Henry', 'Beethoven, Ludwig', 'Begin, Menachem', 'Belloc, Hilaire', 'Bellow, Saul', 'Benchley, Robert', 'Benenson, Peter', 'Ben-Gurion, David', 'Benjamin, Walter', 'Benn, Tony', 'Bennington, Chester', 'Benson, Leana', 'Bent, Silas', 'Bentsen, Lloyd', 'Berger, Ric', 'Bergman, Ingmar', 'Berio, Luciano', 'Berle, Milton', 'Berlin, Irving', 'Berne, Eric', 'Bernhard, Sandra', 'Berra, Yogi', 'Berry, Halle', 'Berry, Wendell', 'Bethea, Erin', 'Bevan, Aneurin', 'Bevel, Ken', 'Biden, Joseph', 'Bierce, Ambrose', 'Biko, Steve', 'Billings, Josh', 'Biondo, Frank', 'Birrell, Augustine', 'Black, Elk', 'Blair, Robert', 'Blair, Tony', 'Blake, William'];
31+
32+
// Array.prototype.filter()
33+
// 1. Filter the list of inventors for those who were born in the 1500's
34+
const fifteen = inventors.filter(inventor => (inventor.year >= 1500 && inventor.year < 1600) );
35+
// Array.prototype.map()
36+
// 2. Give us an array of the inventors' first and last names
37+
const fandl = inventors.map((inventor) => `${inventor.first} ${inventor.last}`);
38+
39+
// Array.prototype.sort()
40+
// 3. Sort the inventors by birthdate, oldest to youngest
41+
const birthdate = inventors.sort((a, b) => {
42+
return b.year - a.year;
43+
})
44+
45+
// Array.prototype.reduce()
46+
// 4. How many years did all the inventors live?
47+
48+
const live = inventors.reduce((total, inventor) => {
49+
return total + (inventor.passed - inventor.year);
50+
}, 0);
51+
52+
// lived
53+
54+
const lived = inventors.reduce((total, inventor) => {
55+
total.push(Object.assign({}, inventor, {
56+
lived: inventor.passed - inventor.year
57+
}));
58+
return total;
59+
}, []);
60+
61+
// 5. Sort the inventors by years lived
62+
63+
const yearsLived = lived.sort((a, b) => b.lived - a.lived);
64+
65+
// 6. create a list of Boulevards in Paris that contain 'de' anywhere in the name
66+
// https://en.wikipedia.org/wiki/Category:Boulevards_in_Paris
67+
68+
69+
// 7. sort Exercise
70+
// Sort the people alphabetically by last name
71+
// const peopleMap = people
72+
// .map(peo => peo.split(', '))
73+
// .reduce((next, prev) =>{
74+
// next.push(prev[1]);
75+
// return next;
76+
// });
77+
// console.log(peopleMap.sort());
78+
const alpha = people.sort((lastOne, nextOne) => {
79+
const [aLast, aFirst] = lastOne.split(', ');
80+
const [bLast, bFirst] = nextOne.split(', ');
81+
return aLast > bLast ? 1 : -1;
82+
});
83+
84+
// 8. Reduce Exercise
85+
// Sum up the instances of each of these
86+
const data = ['car', 'car', 'truck', 'truck', 'bike', 'walk', 'car', 'van', 'bike', 'walk', 'car', 'van', 'car', 'truck' ];
87+
const transportation = data.reduce((obj, item) => {
88+
if (!obj[item]) {
89+
obj[item] = 0;
90+
}
91+
obj[item]++;
92+
return obj;
93+
}, {});
94+
console.log(transportation);
95+
</script>
96+
</body>
97+
</html>

0 commit comments

Comments
 (0)