-3

I have this problem regarding a list of an array I want to basically return a random name inside the array list but I'm having a problem do it.

`\`function randomName(names) {
names = \["john", "Ben", "Jenny", "Michael", "Chloe"\];
Math.random(names.length);
console.log(names);

    return names + "is going to buy lunch today!";

}

randomName();

I want the output to be

Michael (or any name in the array) is going to buy lunch today!

could somehow guide me on how I can do this.

ren
  • 1
  • 1
  • [Math.random](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/random) – toffler Jul 18 '23 at 05:56

1 Answers1

0
const index = Math.floor(Math.random() * names.length);

names[index]
hasmat ali
  • 11
  • 3
  • Answer needs supporting information Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](https://stackoverflow.com/help/how-to-answer). – moken Jul 21 '23 at 12:01