# Feedback after block wont translate to JavaScript

**URL:** <https://discourse.psychopy.org/t/feedback-after-block-wont-translate-to-javascript/14659>\
**Category:** Online experiments\
**Tags:** pavlovia\
**Created:** [June 30, 2020, 8:27am UTC](https://discourse.psychopy.org/t/feedback-after-block-wont-translate-to-javascript/14659 "2020-06-30T08:27:37Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sarah\_Soto](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/sarah_soto/32/6510_2.png) [@Sarah\_Soto](https://discourse.psychopy.org/u/Sarah_Soto)\
**Post date:** [June 30, 2020, 8:27am UTC](https://discourse.psychopy.org/t/feedback-after-block-wont-translate-to-javascript/14659/1 "2020-06-30T08:27:37Z")

</div>

**PsychoPy version** : 3.0.3  
**What are you trying to achieve?:**  
I want the participants to see their performance (% trials correct) after each block, but the automatic translation from Python to Java comes up as syntax error.

On Psychopy, the feedback wors perfect. However, in order to upload it to Pavlovia, I need to have the coding on Java, yet on the box is says “syntax error” (see the image).  
I’m new to coding so I’m not too sure why it is not translating.

Thanks for the help!

 ![image](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/5/3/530fbf2bb0e1f2bfa346da8ebe39ea3bbebe30b2.png)

-

---

<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:** [June 30, 2020, 8:53am UTC](https://discourse.psychopy.org/t/feedback-after-block-wont-translate-to-javascript/14659/2 "2020-06-30T08:53:21Z")

</div>

Hi,

You can’t use this method of formatting strings online. Use “text” + str(variable)

Please do have a look at my crib sheet in the pinned post.

---

<div class="post-metadata">

**Author:** ![phoenix](https://avatars.discourse-cdn.com/v4/letter/p/0ea827/32.png) [@phoenix](https://discourse.psychopy.org/u/phoenix)\
**Post date:** [June 30, 2020, 1:45pm UTC](https://discourse.psychopy.org/t/feedback-after-block-wont-translate-to-javascript/14659/3 "2020-06-30T13:45:15Z")

</div>

Is this the only problem? There is no sum() equivalent in JS.  
@Sarah_Soto, I’ve been there and the only way I found to solve this issue, was to make my own custom variables, increment them every time my participant gave an accurate response and then at the of the block display the accuracy. Then with a conditional loop, after the end of the block (e.g. 80 trials) I reset the Accuracy so that it starts again from 0 for the next block. If you think this could also be done in your case, do let me know to post the code snippets.

---

<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:** [June 30, 2020, 1:49pm UTC](https://discourse.psychopy.org/t/feedback-after-block-wont-translate-to-javascript/14659/4 "2020-06-30T13:49:49Z")

</div>

You’re correct, though sum() can be sorted in code\_JS with

```auto
sum = function (arr) {
return arr.reduce((a,b)=>a+b)
}
OR
sum = (arr) => arr.reduce((a,b)=>a+b)

```

---

<div class="post-metadata">

**Author:** ![Sarah\_Soto](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/sarah_soto/32/6510_2.png) [@Sarah\_Soto](https://discourse.psychopy.org/u/Sarah_Soto)\
**Post date:** [July 1, 2020, 8:49am UTC](https://discourse.psychopy.org/t/feedback-after-block-wont-translate-to-javascript/14659/5 "2020-07-01T08:49:53Z")

</div>

Hi, Thanks for the answer!  
Yet again, I’m very new to coding in Java, so how would I get the “sum = (arr) =\> arr.reduce((a,b)=\>a+b)” with the run results?

---

<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:** [July 1, 2020, 9:25am UTC](https://discourse.psychopy.org/t/feedback-after-block-wont-translate-to-javascript/14659/6 "2020-07-01T09:25:28Z")

</div>

Please take a look at my crib sheet if you haven’t already.

The code I mentioned goes into **code\_JS** in the first routine so that when you want to sum you can just use sum() in Python as normal and have it auto translate.

---

<div class="post-metadata">

**Author:** ![Sarah\_Soto](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/sarah_soto/32/6510_2.png) [@Sarah\_Soto](https://discourse.psychopy.org/u/Sarah_Soto)\
**Post date:** [July 3, 2020, 9:14am UTC](https://discourse.psychopy.org/t/feedback-after-block-wont-translate-to-javascript/14659/7 "2020-07-03T09:14:16Z")

</div>

Hi @phoenix, could you please post the code snippets?  
Many thanks
