0

I would like to make a function that returns some code and am struggling to do so.

function getpresent (place) = {
  type: "single-stim",
  stimulus: getword(place),
  is_html: true,
  timing_stim: 250,
  timing_response: 2000,
  response_ends_trial: false,
  };

This is what I have right now, but it is not working. I need something like...

function getpresent (place) = {
   RETURN [
  type: "single-stim",
  stimulus: getword(place),
  is_html: true,
  timing_stim: 250,
  timing_response: 2000,
  response_ends_trial: false,
],  
};

Is this just a syntax thing? Or is what I'm trying to do just fundamentally flawed? Thanks!

1
  • 1
    You almost have it. Instead of function getpresent (place) = { try function getpresent (place) { return { and end it with a } Commented Aug 30, 2016 at 17:45

4 Answers 4

3

If you like to return an object, then this would work

function getpresent (place) {
    return {
        type: "single-stim",
        stimulus: getword(place),
        is_html: true,
        timing_stim: 250,
        timing_response: 2000,
        response_ends_trial: false
    };
}
Sign up to request clarification or add additional context in comments.

Comments

1

You have a lot of mixed syntax here.

var getpresent = place => ({
  type: 'single-stim',
  stimulus: getword(place),
  is_html: true,
  timing_stim: 250,
  timing_response: 2000,
  response_ends_trial: false
});

Note, this will not work without a transpiler or with a browser that supports ES6 arrow functions. I didn't know which direction you were heading.

An array ([ ]) cannot contain Key/Value pairs like you have in the bottom section of code. Only objects have Key/Value Pairs ({ }).

Also, RETURN is not valid and you must use return in order to return from a function.

Comments

1
function getpresent(place) {
  return {
    type: "single-stim",
    stimulus: getword(place),
    is_html: true,
    timing_stim: 250,
    timing_response: 2000,
    response_ends_trial: false,
  }
}

or with the ES6 syntax:

const getpresent = (place) => ({
  type: "single-stim",
  stimulus: getword(place),
  is_html: true,
  timing_stim: 250,
  timing_response: 2000,
  response_ends_trial: false,
});

Comments

0

Remove the =

proper function syntax:

function myFunction(param) {
    return param;  
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.