Wakefield's Daily Tips

Custom function: defined

In Wakefield's Daily Tips - #74 by wakecarter I dealt with the fact that None doesn’t get translated in a component condition and gets translated to null instead of undefined in a code component by using a try except clause. Today’s tip is a simpler solution. The start condition of the button component can be set to a function which is defined differently in Python and JavaScript.

Add the following Before Experiment.
Python

def defined(x):
    return x != None

JavaScript

function defined(x) {
    return (x !== undefined);
}

Then set the start condition for the button to defined(slider.rating).

The defined function can be used anywhere where 0 is a valid value of x. In other cases (including where x can equal “0”) you can just use if x: