Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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

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;

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();

Joseph Overton
Joseph Overton
4,222 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"