DEV Community

loading...
Cover image for Made sound effects for when I have an error

Made sound effects for when I have an error

jadenconcord profile image Jaden Concord ・1 min read

I recently added some tests to my javascript code for a frontend project.
Here is one of them for example,

test('Eval Template', EvalTemplate('let result = "hola"; return result;'), 'hola');
Enter fullscreen mode Exit fullscreen mode

I thought it would be cool to play some sounds when they passed or failed.

Its actually quite simple, you just wrap your main script in a function like start and use try and catch to check if there was an error and play sound.

function start(){
  error
}
// in test.js
try{
  start();
}
catch(e){
  consoleLogStuff(e);
  playSound();
} // Thats the idea
Enter fullscreen mode Exit fullscreen mode

All you do to to play a sound is

new Audio('path/to/sucsess.mp3').play();
Enter fullscreen mode Exit fullscreen mode

And I didn't forget to make fancy console log stuff.

console.log('%cSUCSESS',
  'color:#111;background:#6e6;padding:16px;font-size:40px;\
  font-weight: bold;display:block;text-align:center;border-radius:16px;');
Enter fullscreen mode Exit fullscreen mode

Alt Text

Now I hear a chime or error sound when testing which is actually quite helpful. If you do this, you should use VS live server or Atom live server extension for best experience.

Discussion (4)

Collapse
cubiclesocial profile image
cubiclesocial

For a good time, make the failure sound be flatulence and accidentally place it into production.

(P.S. It is spelled "success" not "sucsess")

Collapse
jadenconcord profile image
Jaden Concord Author

That would be funny, I worry I might forget to remove it when I deploy. Thanks for the grammar notice.

Collapse
starryepidemic profile image
Collapse
ben profile image
Ben Halpern

This is good 😅

Forem Open with the Forem app