Skip to content
This repository has been archived by the owner on Mar 18, 2024. It is now read-only.

Sound effect added while typing #987

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
Binary file added src/assets/beep.mp3
Binary file not shown.
8 changes: 8 additions & 0 deletions src/js/components/Word.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,15 @@ export function Word(props, ...children) {
onKeydown: e => {
const { key, keyCode, target } = e;
if (keyCode >= 65 && keyCode <= 90) {
new Audio('https://audio.code.org/goal1.mp3').play();
target.value = '';
}
if (key === 'Enter' || keyCode === 13) {
if (props.rebuses[props.current].isAnswered) {
new Audio('https://audio.code.org/win1.mp3').play();
} else {
new Audio('https://audio.code.org/failure1.mp3').play();
}
actions.shake();
}
if (key === 'Backspace' || keyCode === 8) {
Expand All @@ -41,6 +47,8 @@ export function Word(props, ...children) {
if (prevChild !== null && input === '') {
prevChild.focus();
e.preventDefault();
} else {
new Audio('https://audio.code.org/goal2.mp3').play();
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/js/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export const actionsCreators = {
return {};
}
if (input === answer) {
new Audio('https://audio.code.org/win1.mp3').play();
markRebusAsAnswered(rebus.id);
confetti(confettiCanon);
const updatedRebuses = [...rebuses];
Expand Down