# Wakefield's Daily Tips

**URL:** <https://discourse.psychopy.org/t/wakefields-daily-tips/43371>\
**Category:** Blog\
**Tags:** online, pavlovia\
**Created:** [January 1, 2025, 3:36pm UTC](https://discourse.psychopy.org/t/wakefields-daily-tips/43371 "2025-01-01T15:36:55Z")\
**Posts on this page:** 1\
**Showing post:** 27

<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:** [January 26, 2025, 5:42pm UTC](https://discourse.psychopy.org/t/wakefields-daily-tips/43371/27 "2025-01-26T17:42:05Z")

</div>

## Define functions to reduce manual editing of JavaScript code

Following on from [Wakefield's Daily Tips - #6 by wakecarter](https://discourse.psychopy.org/t/wakefields-daily-tips/43371/6), I usually have one code component set to Both in the first routine (which I usually call code\_both). This component can be used to define functions in the **Before Experiment** tab in both Python and JavaScript so that they can be called later in an Auto code component.

For example, here is inverse tan, which doesn’t yet get automatically translated from math.atan() to Math.atan()

Python

```auto
import math
def atan(x):
     return math.atan(x)

```

JavaScript

```auto
function atan(x) {
return Math.atan(x);
}

```

In the experiment itself I can then use atan(x)

> [@Method for implementing isnumeric() in PsychoJS](https://discourse.psychopy.org/t/method-for-implementing-isnumeric-in-psychojs/24502):
>
> I thought I’d share a solution here that I found for a problem I encountered in my experiment that may be useful to others. I had a Python code component that ran the following test: if c.isnumeric(): do\_stuff() Auto-\>JS translation just kept this literal syntax, and this threw an error when running online, because apparently strings in JS do not have an .isnumeric() method. My fix was the following. I did not want to have to manually edit only this line in JS, because I would have to red…

---

_[View the full topic](https://discourse.psychopy.org/t/wakefields-daily-tips/43371)._
