# Calculating standard deviation in PsychoJS

Hi all,

I’m trying to calculate the standard deviation of an array of bars. I have my experiment working locally using the code component in the builder, however I can seem to get it working online. I’m currently using Psychopy version 2020.2.

Below is the python version of my code:

``````#initialize item list, avg, and holding variables
item_list = []
avg = 0
res =0
random.shuffle(set_avg)
end_num = set_avg
for i in range(items):
#create list of 8 items randomly sampled b/t start and end numbers
res = random.randint(strt_num, end_num)
item_list.append(res)
avg = sum(item_list)/items
avg_list.append(avg)
sd = np.std(item_list)
dist =2*sd + end_num
#create variable for each line orientation
or1= item_list
or2 = item_list
or3 = item_list
or4 = item_list
or5 = item_list
or6 = item_list
or7 = item_list
or8 = item_list
``````

And I converted it to JS, but I keep getting the error that “std is not defined”.

I can’t figure out why the std.math() function isn’t working or what the correct replacement should be. Below is my JS code:

``````item_list = [];
avg = 0;
res = 0;
shuffle(set_avg);
end_num = set_avg;
for (var i = 0, _pj_a = items; (i < _pj_a); i += 1) {
res = randint(strt_num, end_num);
item_list.push(res);
}
a = sum(item_list);
avg = (a/items);
avg_list.push(avg);
sd = std.math(item_list);
dist =2*sd + end_num;

or1 = item_list;
or2 = item_list;
or3 = item_list;
or4 = item_list;
or5 = item_list;
or6 = item_list;
or7 = item_list;
or8 = item_list;
``````

I think the issue I’m having is with the std.math() function, so any help on how to calculate the standard deviation of an array would be helpful!