sMilbz
sMilbz

Reputation: 951

Why don't all the words appear

In my word game there is a list of words in a <ul> that holds the words, picture that relates to the word and sound that relates to the word.

When the game is run the script dynamically creates a grid from the amount of words that I state as "maxWords".

The problem I am having is that when I run the program, sometimes one of the words is missing, but the image and sound are still present.

This has only started happening since I made my grid accept bigger words, and I am having trouble trying to find out why this is happening.

Here is the wordList stored in the HTML...

 <ul style="display:none;" id="wordlist">

    <li data-word="mum" data-audio="http://www.wav-sounds.com/cartoon/porkypig2.wav" data-pic="http://www.clker.com/cliparts/5/e/7/f/1195445022768793934Gerald_G_Lady_Face_Cartoon_1.svg.med.png"></li>

    <li data-word="lion" data-audio="http://www.wav-sounds.com/cartoon/bugsbunny2.wav" data-pic="http://www.clker.com/cliparts/c/9/9/5/119543969236915703Gerald_G_Cartoon_Cat_Face.svg.med.png"></li>

    <li data-word="bear" data-audio="http://www.wav-sounds.com/cartoon/daffyduck1.wav" data-pic="http://www.clker.com/cliparts/a/2/c/0/1195440948271207911zeimusu_spotty_dog.svg.med.png"></li>

    <li data-word="beetle" data-audio="http://www.wav-sounds.com/cartoon/daffyduck2.wav" data-pic="http://www.clker.com/cliparts/4/b/4/2/1216180545881311858laurent_scarabe.svg.med.png"></li>

    <li data-word="rat" data-audio="http://www.wav-sounds.com/cartoon/bugsbunny1.wav" data-pic="http://www.clker.com/cliparts/C/j/X/e/k/D/mouse-md.png"></li>

    <li data-word="father" data-audio="http://www.wav-sounds.com/cartoon/porkypig1.wav" data-pic="http://www.clker.com/cliparts/3/a/6/6/119544474191128182Gerald_G_Man_Face_6_-_World_Label.svg.med.png"></li>

  </ul>

The script is rather large so here is a fiddle to have a look at http://jsfiddle.net/smilburn/HZX6k/4/

Upvotes: 3

Views: 139

Answers (1)

Rastko
Rastko

Reputation: 468

Maybe it does not solve the problem, but I see misleading discussion in the comments and probably some easy to fix code faults:

$() syntax is needed for jQuery methods when selecting, and when you put jQuery selector into variable like this:

var yourvar = $("#selector")

You do not need $() any more, you just go yourvar.whatever() for jquery method call. pic variable probably does not have a method show because it is not selector per say.

I suggest using :nth-child() selector instead of current square brackets (array) selector

Now, this solves pic and does not solve biger words mistery :D

For bigger words you need to go through your hardcoded conditions and log any place that could cause code break, I assume it is loop break, to see where problem is.

Upvotes: 1

Related Questions