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 Function Challenge

how to call a parameter / or get a result from it?

https://w.trhou.se/ljl809rvml

I know the code isn't working, stuck on how to return a value from parameters.

2 Answers

You are using console.log(lower); Here lower is a variable of function getMyRand. Which is limiting its scope and you can't directly use that value from outside the function.

An Example of Function which Arguments and Parameter.

function iAmAfunction(parameter){
   return parameter * parameter; //returning a value
}

let squareofNum = iAmAfunction(5); //5 is an argument
console.log(squareofNum);

I would highly recommend you to start the function lectures again to understand the basic terminology.

Yes i will do (i have some holes in my knowledge) thanks for your response

But that doesn't answer his question, because he's trying to log to the console the value of the parameters, dynamically.

For example: document.querySelector('main').innerHTML = `The random number between ${lower} and ${upper} is ${randomNumber(1,100)}`;

I'm trying to figure it out as well, but I believe it's possible only with callbacks, or I'm too asleep at the moment haha.

This is what I'm trying according to your answer.

const randomNumber = (lower, upper) => {
  Math.floor(Math.random() * (lower - 1 + upper)) + 1;

  let numAssigned = randomNumber(1,100);

  let printResult = document.querySelector('main').innerHTML = `The random number between ${lower} and ${upper} is ${numAssigned}`;

  return printResult;
}

// Call the function and pass it different values
randomNumber();

Obviously it throws an error, which says > Uncaught RangeError: Maximum call stack size exceeded

Math.floor(Math.random() * (max - min) ) + min; Start with this. (max = upper, min = lower).