Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript JavaScript Functions Arrow Functions Create Functions Using Arrow Syntax

Alexandru Vlasnita
Alexandru Vlasnita
5,542 Points

Getting an error

I've writte the exact same code in VSC as Guil:

const getRandomNumber = () => { const randomNumber = Math.floor(Math.random() * 6) + 1; return randomNumber; };

and i'm getting "Uncaught ReferenceError: getRandomNumber is not defined at <anonymous>:1:1" in the console.

But when i give it an argument, it works fine.

4 Answers

Joseph Overton
Joseph Overton
4,234 Points

I was having the same problem and getting an error, "SyntaxError: missing ) after argument list" eventually i figured out that i needed to put the unit in quotes when i was calling the function in the console.

getArea(3, 2, sq ft); SyntaxError: missing ) after argument list debugger eval code:1:17 getArea(3, 2, "sq ft"); "6 sq ft"

Dimitar Dimitrov
Dimitar Dimitrov
11,800 Points

It works just fine i just tested it with my VSC

const getRandomNumber = () => {
  const randomNumber = Math.floor(Math.random() * 6) + 1;
  return randomNumber;
};
console.log(getRandomNumber());

The code is spot on. Do you have the correct .js file linked to your index.html file?

When you call it, make sure to use the parenthesis at the end even if you aren't passing an argument, like getRandomNumber();