# Playing a sound to match something in an array

**URL:** <https://forum.kirupa.com/t/playing-a-sound-to-match-something-in-an-array/308155>\
**Category:** web dev\
**Created:** [April 17, 2010, 7:35pm UTC](https://forum.kirupa.com/t/playing-a-sound-to-match-something-in-an-array/308155 "2010-04-17T19:35:24Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![angelwingsx](https://avatars.discourse-cdn.com/v4/letter/a/6f9a4e/32.png) [@angelwingsx](https://forum.kirupa.com/u/angelwingsx)\
**Post date:** [April 17, 2010, 7:35pm UTC](https://forum.kirupa.com/t/playing-a-sound-to-match-something-in-an-array/308155/1 "2010-04-17T19:35:24Z")

</div>

Hello.

I’m creating a matching game with letters. I would like the sound to play with the associated letter so that the user can hear how it’s pronounced correctly when they click on the image.

Here is the function I’m having difficulty with. After the program identifies which image has been selected I would like it to play the corresponding sound with it.

```auto

function showImg(x){
  if (clickCount >= 2) checkAns();
  pics[clickCount] = x;
  clickCount +=1;
  document.getElementById(x).src="pics/pic"+thePics[x]+".jpg";
  //document.getElementById(x).innerHTML= "<embed src=\sounds\sound"+x+".mp3\" hidden=\"true\" autostart=\"true\" loop=\"false\" />";
  alert(x);
 }
 
 

```

Here is an example of my table of cards:

```auto

<table align="center">
<tr>
<td><img id="0" src="pics/backCard.jpg" width="100" height="120" alt="1" onclick="showImg(0);" /></td>
 
</table>

```
