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 Basics (Retired) Creating Reusable Code with Functions Giving Information to Functions

MICHAEL P
MICHAEL P
5,191 Points

"Uncaught reference error" in JavaScript-Please help!Followed Video and Still Have This Problem!

Hi,

I followed the code, and typed it exactly the way that the teacher put it in. For some reason I am getting an error on . I am hoping that someone can help me make sense of this. I am also posting my code.

random.js.13

function getRandomNumber( upper ) {
  var randomNumber = Math.floor( Math.random() * upper ) + 1; 
  return randomNumber;
}
/*
console.log( getRandomNumber(6) );
console.log( getRandomNumber(100) );
console.log( getRandomNumber(10000) );
console.log( getRandomNumber(2) );
*/
function getArea(width, legth) {
  var area = width * legth;
  return area + "" + unit ;
}
console.log(getArea(10, 20, 'sq ft'));

3 Answers

You forgot to add the unit as a parameter, let me know if you need more explanation

function getRandomNumber( upper ) { 
  var randomNumber = Math.floor( Math.random() * upper ) + 1; return randomNumber; }
 function getArea(width, legth, unit) { /*add unit parameter*/
  var area = width * legth; return area + "" + unit ; 
} 
console.log(getArea(10, 20, 'sq ft'))

One thing to note is "random.js.13" means that an error is occurring on line 13 in the random.js file. Sometimes those are helpful hints in debugging.

agreed Sean. That's how I found the error.

MICHAEL P
MICHAEL P
5,191 Points

Thanks guys. The thing is, that the teacher "Dave" typed the code exactly as I had it. I don't recall him typing that extra parameter.

Would the "add unit parameter", be the "sq ft"?

So, John Larson, is the code that you typed correct? With the "add unit parameter"?

Hi Michael,

John put the "add unit parameter" as a comment since it is wrapped in /* insert comment here */. He added the unit parameter right before that in the (). The string 'sq ft' in the second code example would be the unit parameter.

Below we created a function named getArea.

function getArea(width, length, unit)  {
  var area = width * length;
  return area + " " + unit ;
}

Then when call the function, we pass it the three parameters(width, length, unit).

console.log(getArea(10, 20, 'sq ft'));

Running the code above would write "200 sq ft" to the console.

I hope that didn't confuse you. Let us know if you need more clarification. Thanks, Sean