Unable to convert NaN to a number - found segment of code responsible but still can't debug

Exact error:

  • when converting an object to its numerical form
  • unable to convert NaN to a number

I’ve found the segment of code responsible for this, but I’m not sure how to debug it:

var pointA = minForCertainty.getRating();
var pointB = maxForCertainty.getRating();

if ((pointA !== null) && (Number.isNaN(pointA) == false)){
if ((pointB !== null) && (Number.isNaN(pointB) == false)) {
linewidth = pointB - pointA;
lineposition = ((pointA + pointB) / 2);

if (((endkey.keys !== undefined) && (endkey.keys === “space”))) {
thisExp.addData(‘linewidth’, linewidth)
thisExp.addData(‘lineposition’, lineposition)

(in ‘Every Frame’ - initial values of linewidth, lineposition, pointA and pointB have been set in begin experiment & before experiment)

I’ve tried looking through the forum and checking the python to JS cribsheet, but nothing seems to come up. The python version of this code works offline:

pointA = minForCertainty.getRating()
pointB = maxForCertainty.getRating()

if pointB is not None:
if pointA is not None:
linewidth = pointB - pointA
lineposition = (pointA + pointB) / 2

if ‘space’ in endkey.keys:
thisExp.addData(‘linewidth’, linewidth)
thisExp.addData(‘lineposition’, lineposition)

Thank you!

Does this help?

I did look at that thread, sadly it didn’t help :frowning: Followed the advice to use Number.isNaN but it didn’t seem to make a difference

So I found a solution from Demonstrate the slider value - Online experiments - PsychoPy - slider.getRating doesn’t work on JS, which I did not know!! Use slider._markerPos instead (see Becca’s comment on linked post).

@wakecarter possible addition to the cribsheet?

1 Like