Reputation: 19476
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?
Upvotes: 0
Views: 422
Reputation: 6740
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.
Upvotes: 3