Skip to content

final 1 #694

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions 01 - JavaScript Drum Kit/index-START.html
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,25 @@
<audio data-key="76" src="sounds/tink.wav"></audio>

<script>

function removeTransition(e) {
if (e.propertyName !== 'transform') return;
e.target.classList.remove('playing');
}

function playSound(e) {
const audio = document.querySelector(`audio[data-key="${e.keyCode}"]`);
const key = document.querySelector(`div[data-key="${e.keyCode}"]`);
if (!audio) return;

key.classList.add('playing');
audio.currentTime = 0;
audio.play();
}

const keys = Array.from(document.querySelectorAll('.key'));
keys.forEach(key => key.addEventListener('transitionend', removeTransition));
window.addEventListener('keydown', playSound);
</script>


Expand Down
21 changes: 21 additions & 0 deletions 02 - JS and CSS Clock/index-START.html
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,34 @@
background: black;
position: absolute;
top: 50%;
transform-origin: 100%;
transform:rotate(90deg);
transition: all 0.05s;
transition-timing-function:cubic-bezier(0.19, 1, 0.22, 1);
}

</style>

<script>
const secondHand = document.querySelector('.second-hand');
const minHand = document.querySelector('.min-hand');
const hourHand = document.querySelector('.hour-hand');
function setDate() {
const now = new Date();

const seconds = now.getSeconds();
const secondDegrees =((seconds / 60)* 360);
secondHand.style.transform = `rotate(${secondDegrees}deg)`;

const minutes = now.getMinutes();
const minuteDegrees = ((minutes / 60)* 360);
minHand.style.transform = `rotate(${minuteDegrees}deg)`;

const hours = now.getHours();
const hourDegrees = ((hours / 24)* 360);
hourHand.style.transform = `rotate(${hourDegrees}deg)`;
}
setInterval(setDate, 1000);
</script>
</body>
</html>
25 changes: 23 additions & 2 deletions 03 - CSS Variables/index-START.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,22 @@ <h2>Update CSS Variables with <span class='hl'>JS</span></h2>
<input id="base" type="color" name="base" value="#ffc600">
</div>

<img src="https://source.unsplash.com/7bwQXzbF6KE/800x500">
<img src="https://i.pinimg.com/originals/e0/c3/71/e0c371b8862e6dabf41836b503bcbd8a.jpg">

<style>

:root {
--base:#ffff00;
--spacing:20px;
--blur:10px;
}
img {
background: var(--base);
padding:var(--spacing);
filter:blur(var(--blur));
}
.hl {
color:var(--base);
}
/*
misc styles, nothing to do with CSS variables
*/
Expand All @@ -46,6 +58,15 @@ <h2>Update CSS Variables with <span class='hl'>JS</span></h2>
</style>

<script>
const inputs = document.querySelectorAll('.controls input');

function handleUpdate() {
const suffix = this.dataset.sizing || '';
document.documentElement.style.setProperty(`--${this.name}`, this.value + suffix);
}

inputs.forEach(input => input.addEventListener('change', handleUpdate));
inputs.forEach(input => input.addEventListener('mousemove', handleUpdate));
</script>

</body>
Expand Down
53 changes: 50 additions & 3 deletions 04 - Array Cardio Day 1/index-START.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,28 +38,75 @@

// Array.prototype.filter()
// 1. Filter the list of inventors for those who were born in the 1500's
const fifteen = inventors.filter(inventor => (inventor.year >= 1500 && inventor.year < 1600));

console.table(fifteen);

// Array.prototype.map()
// 2. Give us an array of the inventors first and last names
// 2. Give us an array of the inventor first and last names
const fullNames = inventors.map(inventor => `${inventor.first} ${inventor.last}`);
console.log(fullNames);

// Array.prototype.sort()
// 3. Sort the inventors by birthdate, oldest to youngest
// const ordered = inventors.sort(function(a, b) {
// if(a.year > b.year) {
// return 1;
// } else {
// return -1;
// }
// });

const ordered = inventors.sort((a, b) => a.year > b.year ? 1 : -1);
console.table(ordered);

// Array.prototype.reduce()
// 4. How many years did all the inventors live all together?
// 4. How many years did all the inventors live?
const totalYears = inventors.reduce((total, inventor) => {
return total + (inventor.passed - inventor.year);
}, 0);

console.log(totalYears);

// 5. Sort the inventors by years lived
const oldest = inventors.sort(function(a, b) {
const lastInventor = a.passed - a.year;
const nextInventor = b.passed - b.year;
return lastInventor > nextInventor ? -1 : 1;
});
console.table(oldest);

// 6. create a list of Boulevards in Paris that contain 'de' anywhere in the name
// https://en.wikipedia.org/wiki/Category:Boulevards_in_Paris

// const category = document.querySelector('.mw-category');
// const links = Array.from(category.querySelectorAll('a'));
// const de = links
// .map(link => link.textContent)
// .filter(streetName => streetName.includes('de'));

// 7. sort Exercise
// Sort the people alphabetically by last name
const alpha = people.sort((lastOne, nextOne) => {
const [aLast, aFirst] = lastOne.split(', ');
const [bLast, bFirst] = nextOne.split(', ');
return aLast > bLast ? 1 : -1;
});
console.log(alpha);

// 8. Reduce Exercise
// Sum up the instances of each of these
const data = ['car', 'car', 'truck', 'truck', 'bike', 'walk', 'car', 'van', 'bike', 'walk', 'car', 'van', 'car', 'truck' ];
const data = ['car', 'car', 'truck', 'truck', 'bike', 'walk', 'car', 'van', 'bike', 'walk', 'car', 'van', 'car', 'truck', 'pogostick'];

const transportation = data.reduce(function(obj, item) {
if (!obj[item]) {
obj[item] = 0;
}
obj[item]++;
return obj;
}, {});

console.log(transportation);

</script>
</body>
Expand Down
35 changes: 34 additions & 1 deletion 05 - Flex Panel Gallery/index-START.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
.panels {
min-height: 100vh;
overflow: hidden;
display: flex;
}

.panel {
Expand All @@ -44,6 +45,11 @@
font-size: 20px;
background-size: cover;
background-position: center;
flex: 1;
justify-content: center;
align-items: center;
display: flex;
flex-direction: column;
}

.panel1 { background-image:url(https://source.unsplash.com/gYl-UtwNg_I/1500x1500); }
Expand All @@ -57,7 +63,18 @@
margin: 0;
width: 100%;
transition: transform 0.5s;
border: 1px solid red;
flex:1 0 auto;
display: flex;
justify-content: center;
align-items: center;
}
.panel > *:first-child {transform: translateY(-100%);}
.panel.open-active > *:first-child {transform: translateY(0);}
.panel > *:last-child {transform: translateY(100%);}
.panel.open-active > *:first-child {transform: translateY(0);}



.panel p {
text-transform: uppercase;
Expand All @@ -72,6 +89,7 @@

.panel.open {
font-size: 40px;
flex:5 ;
}

</style>
Expand Down Expand Up @@ -106,7 +124,22 @@
</div>

<script>

const panels = document.querySelectorAll('.panel');

function toggleOpen() {
console.log('Hello');
this.classList.toggle('open');
}

function toggleActive(e) {
console.log(e.propertyName);
if (e.propertyName.includes('flex')) {
this.classList.toggle('open-active');
}
}

panels.forEach(panel => panel.addEventListener('click', toggleOpen));
panels.forEach(panel => panel.addEventListener('transitionend', toggleActive));
</script>


Expand Down
38 changes: 38 additions & 0 deletions 06 - Type Ahead/index-START.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,44 @@
</form>
<script>
const endpoint = 'https://gist.githubusercontent.com/Miserlou/c5cd8364bf9b2420bb29/raw/2bf258763cdddd704f8ffd3ea9a3e81d25e2c6f6/cities.json';
const cities = [];
fetch(endpoint)
.then(blob => blob.json())
.then(data => cities.push(...data));

function findMatches(wordToMatch, cities) {
return cities.filter(place => {
// here we need to figure out if the city or state matches what was searched
const regex = new RegExp(wordToMatch, 'gi');
return place.city.match(regex) || place.state.match(regex)
});
}

function numberWithCommas(x) {
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',');
}

function displayMatches() {
const matchArray = findMatches(this.value, cities);
const html = matchArray.map(place => {
const regex = new RegExp(this.value, 'gi');
const cityName = place.city.replace(regex, `<span class="hl">${this.value}</span>`);
const stateName = place.state.replace(regex, `<span class="hl">${this.value}</span>`);
return `
<li>
<span class="name">${cityName}, ${stateName}</span>
<span class="population">${numberWithCommas(place.population)}</span>
</li>
`;
}).join('');
suggestions.innerHTML = html;
}

const searchInput = document.querySelector('.search');
const suggestions = document.querySelector('.suggestions');

searchInput.addEventListener('change', displayMatches);
searchInput.addEventListener('keyup', displayMatches);

</script>
</body>
Expand Down
15 changes: 12 additions & 3 deletions 07 - Array Cardio Day 2/index-START.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,25 @@

// Some and Every Checks
// Array.prototype.some() // is at least one person 19 or older?
const isAdult = people.some(person => (new Date()).getFullYear() - person.year >= 19);
console.log(isAdult);
// Array.prototype.every() // is everyone 19 or older?

const allAdults = people.every(person => (new Date()).getFullYear() - person.year >= 19);
console.log(allAdults);
// Array.prototype.find()
// Find is like filter, but instead returns just the one you are looking for
// find the comment with the ID of 823423

const comment = comments.find(comment => comment.id === 823423);
console.log(comment);
// Array.prototype.findIndex()
// Find the comment with this ID
// delete the comment with the ID of 823423

const index = comments.findIndex(comment => comment.id === 823423);
console.log(index);
const newComments = [
...comments.slice(0, index),
...comments.slice(index + 1)
]
</script>
</body>
</html>
53 changes: 53 additions & 0 deletions 08 - Fun with HTML5 Canvas/index-START.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,59 @@
<body>
<canvas id="draw" width="800" height="800"></canvas>
<script>
const canvas = document.querySelector('#draw');
const ctx = canvas.getContext('2d');
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
ctx.strokeStyle = '#BADA55';
ctx.lineJoin = 'round';
ctx.lineCap = 'round';
ctx.lineWidth = 100;

let isDrawing = false;
let lastX = 0;
let lastY = 0;
let hue = 0;
let direction = true;
function draw(e) {
if (!isDrawing) return;
console.log(e);
ctx.strokeStyle = `hsl(${hue}, 100%, 50%)`;
ctx.beginPath();
ctx.moveTo(lastX, lastY);
ctx.lineTo(e.offsetX, e.offsetY);
ctx.stroke();
[lastX, lastY] = [e.offsetX, e.offsetY];

hue++;
if (hue >= 360) {
hue = 0;
}
if (ctx.lineWidth >= 100 || ctx.lineWidth <= 1) {
direction = !direction;
}

if(direction) {
ctx.lineWidth++;
} else {
ctx.lineWidth--;
}

}

canvas.addEventListener('mousedown', (e) => {
isDrawing = true;
[lastX, lastY] = [e.offsetX, e.offsetY];
});


canvas.addEventListener('mousemove', draw);
canvas.addEventListener('mouseup', () => isDrawing = false);
canvas.addEventListener('mouseout', () => isDrawing = false);




</script>

<style>
Expand Down
Loading