0

Why this is NaN in JavaScript?

alert(typeof settings.mouse.x + ' --- ' + typeof getScalePercent((bg_w - a_w)/2, settings.bg.perc_position));
// alerts: number --- number

var pos_x = settings.mouse.x - getScalePercent((bg_w - a_w)/2, settings.bg.perc_position);    
alert(pos_x);
// alerts: NaN

// this syntax because a jQuery plug-in
var getScalePercent = function (value, perc) {
    return value * perc / 100;
}

// settings.mouse.x == 102 basically an integer
// getScalePercent(...) == 10 or 12.0390394028 basically an number

alert(settings.mouse.x + ' (' + typeof settings.mouse.x + ') --- ' + getScalePercent(((bg_w - a_w)/2), settings.bg.perc_position) + '(' + typeof getScalePercent(((bg_w - a_w)/2), settings.bg.perc_position) + ')');
// returns 102 (number) --- 12.000340563 (number)

Where I'm wrong?

vitto
  • 19,094
  • 31
  • 91
  • 130

1 Answers1

3

My guess is that getScalePercent is returning NaN . Since typeof NaN is returning number. Check the function whether it does what you expect to do.

ysrb
  • 6,693
  • 2
  • 29
  • 30
  • there was an error on passing a `undefined` val instead of a `number` in the method `getScalePercent` thank you! – vitto Feb 05 '12 at 10:48