tags:

views:

43

answers:

1

This isn't working:

function checkIt(String rep) {
         if (counter[$(rep).val()] == undefined) {
         count++;
         result = Math.round((count * 100 )/howMany);
         $('.percent').text(result);
         $('#perc_in').animate({'width': result+'%'}, 500);
         counter[$(this).val()] = 1;
         $('#counter').text(result);
         }
}

Like, at all... <_< I mean I think I am doing the function wrong.

Then inside the case statement I have this:

checkIt($(this).val());
+3  A: 

Javascript is weak typed, so what in the world is this?

function checkIt(String rep) {

Just change it to

function checkIt(rep) {

It's also a bit odd that you are try to create a new jQuery object from the value of another form element. And this line:

if (counter[$(rep).val()] == undefined) {

This may be a little dangerous if you're just checking for the non-existence of an array element, since $(rep).val() could also be undefined depending on the situation.

Yi Jiang
Also, it is unclear where `count` is defined, and what it is used for (if at all).
karim79
@karim Well, let's assume that all variables are declared. If not we could just as easily say that jQuery isn't properly load ;). As for uses erm... some sort of global count on how many times this function has been called?
Yi Jiang
@Yi Jiang - good point. Would be good to know, as it looks downright confusing :) I voted you up btw, that wasn't a 'gripe' but an innocuous (and I hoped useful) comment :)
karim79
OK that worked. Thanks!
Dan
OK that seems to work for only two of cases.... and I get undefnied when i do $(rep).val()...
Dan
@Dan Two possible reasons: 1. `rep` isn't a valid selector, so jQuery's returning undefined. 2. The element selected by `$(rep)` doesn't have a `value` attribute. Not that I didn't warn you on that in the answer...
Yi Jiang
It only works for the first two case uses and then it stops... so I'm going to see what I did wrong tomorrow or well it didn't work corerct in the first place but we shall see!
Dan
@Dan - It'd help if you posted all your code, since there seem be errors outside of the code currently posted.
Peter Ajtai
index.php: http://www.xasad.pastebin.com/btPyt0Y8theGame.js: http://www.xasad.pastebin.com/9z7UyKF2
Dan
You're right - it's somethign in that code. I stripped it of it's execssive code with just the bare bones and it worked fine.
Dan