JavaScript Audio does not play on keyboard event with JS? does audio play through hdmi,does audio play through displayport,

I have a key (s) that I want to press in order to create a keyboard event which would be a sound that I have linked in my file. The sound src is correct, and from what I know, so is my JavaScript. Is there a step that I am not aware of for adding sound in a HTML file?

My code:

<!DOCTYPE html>
<html lang="en">
    <head>
        <!-- Required meta tags -->
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

        <!-- Bootstrap CSS -->
        <link rel="stylesheet" target='_blank' href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" integrity="sha384-rwoIResjU2yc3z8GV/NPeZWAv56rSmLldC3R/AZzGRnGxQQKnKkoFVhFQhNUwEyJ" crossorigin="anonymous">
        <link rel="stylesheet" target='_blank' href="style.css" type="text/css">
    </head>
    <body>

        <div class="container">
            <div class="row">

                <div class="col-12">
                    <div data-key="83" class="key">
                        <kbd>s</kbd>
                        <span class="sound">clap</span>
                    </div>
                </div>

            </div>
        </div>

        <audio data-key="83" src="jap/big_taiko.wav"></audio>



        <script>
            window.addEventListener('keydown', function(e) {
                const audio = document.querySelector('audio[data-key="${e.keyCode}"]');
                if (!audio) return;
                audio.play();
            });
        </script>
    </body>
</html>
Answer:1

Use document.addEventListener instead of window.addEventListener.

Also i changed querySelector audio[data-key="${e.keyCode}"] with 'audio[data-key="'+e.keyCode+'"]'

  document.addEventListener('keydown', function(e) { 
     const audio = document.querySelector('audio[data-key="'+e.keyCode+'"]');
                if (!audio) return;
                audio.play();
            });
  <audio data-key="83" src="http://www.stephaniequinn.com/Music/Allegro%20from%20Duet%20in%20C%20Major.mp3"></audio>
Answer:2

I have a component built with es6 class syntax. It's a simple component with just a diverse and some styling. Then, on the parent component (called app), I'd like to render that component and give it ...

I have a component built with es6 class syntax. It's a simple component with just a diverse and some styling. Then, on the parent component (called app), I'd like to render that component and give it ...

  1. react component does not rerender on props change
  2. react component does not rerender on state change
  3. react component does not contain a default export
  4. react component does not update on state change
  5. react component does not rerender
  6. react component does not update
  7. react component does not render
  8. react component does not mount
  9. react component doesn't unmount
  10. react component doesn't update on props change
  11. react component does not rerender after setstate
  12. react component does not contain an export named
  13. react child component does not update
  14. react redux component does not update
  15. react router component does not render
  16. react redux component does not rerender
  17. react when does component unmount
  18. react when does component rerender
  19. react when does component render
  20. react when does component update

I have a if block condition. I need to write test case for that if condition in jasmine javascript.While referring this website https://jasmine.github.io/2.1/custom_matcher.html This is my code in ...

I have a if block condition. I need to write test case for that if condition in jasmine javascript.While referring this website https://jasmine.github.io/2.1/custom_matcher.html This is my code in ...

  1. write conditional statement in excel
  2. write conditional statement
  3. write conditional statement in sql
  4. write conditional statement in javascript
  5. write conditional statement java
  6. write conditional statement mysql
  7. write conditional statement ruby
  8. write the conditional statement that the venn diagram illustrates
  9. write a conditional statement from each of the following
  10. write a conditional statement for a venn diagram
  11. write the conditional statement and converse within the biconditional
  12. write each conditional statement
  13. write a conditional statement and contrapositive
  14. how to write conditional statement in c#
  15. how to write conditional statement in html
  16. how to write conditional statement in matlab
  17. how to write conditional statement in latex
  18. how to write conditional statement in r
  19. how to write conditional statement in ssis
  20. how to write conditional statement in jquery

I use this code to show pop-up to users only once per session. It works but it will show once only on a specific URL. For example, if a user visits www.mydomain.com/some-url-1 it will show only once ...

I use this code to show pop-up to users only once per session. It works but it will show once only on a specific URL. For example, if a user visits www.mydomain.com/some-url-1 it will show only once ...

  1. jquery cookie show popup once
  2. jquery cookie show div only once
  3. jquery cookie show hide div
  4. jquery show cookie

I feel like I'm losing my mind because the answer should be so simple, I'm new to angular and nodejs and I'm trying to make an application that combines them both. "Error: [$injector:nomod] Module '...

I feel like I'm losing my mind because the answer should be so simple, I'm new to angular and nodejs and I'm trying to make an application that combines them both. "Error: [$injector:nomod] Module '...

  1. angular nodejs module
  2. angular import nodejs module
  3. angular use nodejs module
  4. angular import node module js