Skip to content

fixing bug drumkit, alternative solution to ex 6 #458

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
45 changes: 32 additions & 13 deletions 01 - JavaScript Drum Kit/index-FINISHED.html
Original file line number Diff line number Diff line change
Expand Up @@ -58,23 +58,42 @@
<audio data-key="76" src="sounds/tink.wav"></audio>

<script>
function removeTransition(e) {
if (e.propertyName !== 'transform') return;
e.target.classList.remove('playing');
}
// 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);

// ALTERNATIVE =================================================================>
function playSound(key) {

const audio = document.querySelector(`audio[data-key="${key.keyCode}"]`);
const keyAnimation = document.querySelector(`.key[data-key="${key.keyCode}"]`);

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

function playSound(e) {
const audio = document.querySelector(`audio[data-key="${e.keyCode}"]`);
const key = document.querySelector(`div[data-key="${e.keyCode}"]`);
if (!audio) return;
setTimeout(() => {
keyAnimation.classList.remove('playing');
}, 150);

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

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

Expand Down
3 changes: 3 additions & 0 deletions 04 - Array Cardio Day 1/index-FINISHED.html
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@
return lastInventor > nextInventor ? -1 : 1;
});
console.table(oldest);
// ALTERNATIVE =================================================================================>
const sortByLiving = inventors.sort((a,b) => (a.passed - a.year) > (b.passed - b.year) ? -1 : 1);
console.table(sortByLiving)

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