When I call the function, it must display A random person's name.
CodePudding user response:
You should correct names.length to listof names.length for example
CodePudding user response:
// You only add a paramter when you provide an argument when calling the function, for example if the listOfNames array was outside the function
function whosPaying() {
let listOfNames = ["Mohamed", "Ahmed", "Farah", "Yusuf", "Dahir"];
let numberOfPeople = Math.floor(Math.random() * listOfNames.length);
let randomPerson = listOfNames[numberOfPeople];
return randomPerson " is going to buy lunch today!";
}
console.log(whosPaying());