I'm new to programming and for the moment I'm learning JavaScript using a combination of online courses. One challenge I'm working on is to use a function to return a random string from an array. That part itself was easy, but it seems like I need to be able to create the array from the input I give when I call the function. As an example, if I were to create a function like this:
function namePicker(names);
And I then called the function and gave it this input:
namePicker("Billy","Timmy","Johnny");
then I should be able to use the input to create an array of these names. However, when I tried to work this into the code for the random name picker, only the first name I gave would return to me.
What am I doing wrong here? Here's the full code I've been working on:
function lunchClubLottery(names) {
var lunchClub = [names];
var randomNumber=Math.floor(Math.random()*lunchClub.length);
return lunchClub[randomNumber];
}