1

That's the function:

function randomNum(n) {
  const numbers = [1,2,3,4,5,6,7,8,9,10]
  if(numbers.includes(n)) {
    console.log('ok')
  } else {
    console.log('Choose a value between 1 and 10')
  }
}
console.log(randomNum(5))

Sorry if it's a simple problem, but i can't figure it out, i'm kinda new to programing. The function is returning 'undefined' after 'ok' or 'Choose a value between 1 and 10'.

0

2 Answers 2

0

Instead of using console.log(<value>);, try using a return <value>; statement. At the moment, your code runs the function randomNum, prints the result to the console, then prints the return value from the function. Without an explicit return statement, this return value is undefined.

I hope this helps!

Sign up to request clarification or add additional context in comments.

Comments

0

Your function doesn't return anything, it only logs. To fix add return.

function randomNum(n) {
    const numbers = [1,2,3,4,5,6,7,8,9,10]
    if(numbers.includes(n)) {
      return 'ok';
    } else {
      return 'Choose a value between 1 and 10';
    }
  }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.