1

I'm getting an illegal return statement in the line of my code near the bottom that says: return points

createPoints(x, y, length, depth, angle, points)
{
  if(depth > 0)
  {
    //draws line
    points.push((x + length) * Math.sin(angle));
    points.push((y + length) * Math.cos(angle));

    //draw left branch
    angle += Math.PI / 4;
    createPoints(treeString, (x + length/2) * Math.sin(angle), (y + length/2) * Math.cos(angle), depth - 1, points);

    //goes back
    points.push(x);
    points.push(y);

    //draw right branch
    angle -= Math.PI / 2;
    createPoints(treeString, (x + length/2) * Math.sin(angle), (y + length/2) * Math.cos(angle), depth - 1, points);
    return points;
  }
  return;
}

the function is supposed to plot points in an array for a fractal tree to use in webgl. I'm not sure why I'm getting my error and unfortunately, neither my professor nor TA know either.

4
  • Since you can only use return within a Function, you must declare createPoints as such, i.e function createPoints(x, y, length, depth, angle, points) { // function body ... } . Check the MDN link about functions and to see alternative ways to declare one. Commented Oct 11, 2019 at 20:00
  • Can you show the full error (a screenshot, if necessary) and more context for the code? Commented Oct 11, 2019 at 20:00
  • Oh, is this code just at the top level? You’re trying to use a shorthand that only works in classes and object literals. There needs to be some kind of declaration involved, like @NikKyriakides said. Commented Oct 11, 2019 at 20:01
  • can you share the whole code so that we can debug? Commented Oct 11, 2019 at 20:05

1 Answer 1

1

you are missing function keyword for your function name
try below pattern, it will help you .

 function createPoints () {} 

let createPoints = () => {}
Sign up to request clarification or add additional context in comments.

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.