# Code output is NaN

**URL:** <https://discourse.psychopy.org/t/code-output-is-nan/13048>\
**Category:** Online experiments\
**Created:** [May 5, 2020, 10:21pm UTC](https://discourse.psychopy.org/t/code-output-is-nan/13048 "2020-05-05T22:21:51Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vinzenz](https://avatars.discourse-cdn.com/v4/letter/v/898d66/32.png) [@Vinzenz](https://discourse.psychopy.org/u/Vinzenz)\
**Post date:** [May 5, 2020, 10:21pm UTC](https://discourse.psychopy.org/t/code-output-is-nan/13048/1 "2020-05-05T22:21:51Z")

</div>

URL of experiment: [https://gitlab.pavlovia.org/DuderstadtV/leson\_onlinepilot\_adj\_debug](https://gitlab.pavlovia.org/DuderstadtV/leson_onlinepilot_adj_debug)

Description of the problem:

Dear all,

The following code should generate a number between 485 and 515:

```auto
Number.parseInt((orange * 1000));

```

orange is a variable defined in an outer loop with values between 0,485 and 0,515 out of an excel sheet. I use this code to select different stimuli and it works just fine in another experiment, but I get NaN as output right now. The only clue I have is that maybe JS has problems to use variables out of an outer loop. Does anyone know a solution?

Kind regards,  
Vinzenz

---

<div class="post-metadata">

**Author:** ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)\
**Post date:** [May 5, 2020, 10:40pm UTC](https://discourse.psychopy.org/t/code-output-is-nan/13048/2 "2020-05-05T22:40:26Z")

</div>

It might be that orange is being read as text. You could try adding 1 (and possibly also displaying the result) to it to see if you get an error.

Best wishes

Wakefield

---

<div class="post-metadata">

**Author:** ![Vinzenz](https://avatars.discourse-cdn.com/v4/letter/v/898d66/32.png) [@Vinzenz](https://discourse.psychopy.org/u/Vinzenz)\
**Post date:** [May 5, 2020, 11:12pm UTC](https://discourse.psychopy.org/t/code-output-is-nan/13048/3 "2020-05-05T23:12:25Z")

</div>

That does not seem to be the problem. I get the notification that orange is undefined. This is strange, because the other variables out of the excel sheet work just fine.

---

<div class="post-metadata">

**Author:** ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)\
**Post date:** [May 6, 2020, 4:10am UTC](https://discourse.psychopy.org/t/code-output-is-nan/13048/4 "2020-05-06T04:10:48Z")

</div>

Give orange a value in a Begin Experiment block.

> **[PsychoPy Python to Javascript crib sheet](https://docs.google.com/document/d/13jp0QAqQeFlYSjeZS0fDInvgaDzBXjGQNe4VNKbbNHQ/edit?usp=sharing)**
>
> PsychoPy Python to Javascript crib sheet Compiled by Wakefield Morys-Carter, Oxford Brookes University PsychoPy 2020 has an automatic Python to Javascript translation tool. This document contains information about code that is not translated...

---

<div class="post-metadata">

**Author:** ![Vinzenz](https://avatars.discourse-cdn.com/v4/letter/v/898d66/32.png) [@Vinzenz](https://discourse.psychopy.org/u/Vinzenz)\
**Post date:** [May 6, 2020, 9:06am UTC](https://discourse.psychopy.org/t/code-output-is-nan/13048/5 "2020-05-06T09:06:51Z")

</div>

If I do this the experiment works, but the experiment only uses the value out of this block. Unfortunately my value for orange has to vary in every trial depending on the value named in the excel sheet.

---

<div class="post-metadata">

**Author:** ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)\
**Post date:** [May 6, 2020, 9:36am UTC](https://discourse.psychopy.org/t/code-output-is-nan/13048/6 "2020-05-06T09:36:58Z")

</div>

The values in the spreadsheet should have replaced the initial value. Have you double checked your capitalisation of orange in your spreadsheet? Does the experiment work locally?

---

<div class="post-metadata">

**Author:** ![Vinzenz](https://avatars.discourse-cdn.com/v4/letter/v/898d66/32.png) [@Vinzenz](https://discourse.psychopy.org/u/Vinzenz)\
**Post date:** [May 6, 2020, 1:37pm UTC](https://discourse.psychopy.org/t/code-output-is-nan/13048/7 "2020-05-06T13:37:34Z")

</div>

It works fine in a local version. The problem is the missing information from the spreadsheet.
