I want to create a function that when I call it, I can give a gender and it will return me a random name. The problem is that I want it to be reusable which is where I am running into difficulty.
var Name = '';
var Gender = '';
var NameChild1(){
var Child1Gender = 'Male'
Child1Name = NameFunction(Child1Gender, Child1Name)
}
function NameFunction(Gender, Name) {
var NameChance1 = Math.floor(Math.random() * 10) + 1;
NameChance1 = NameChance1.toString();
d3.csv('Names.csv', function(NameData) {
var NameFilter = NameData.filter(function(d) {
return (d.Rank == NameChance1)
})
if (Gender == 'Female') {
Name = NameFilter[0]['NameFemale'];
return (Name);
} else if (Gender == 'Male') {
return (Name);
};
});
};
The name filter does work in the if statements if I do console.log inside them - but it doesn't return past that.
Does anyone know what the problem is?
Also, this is the CSV if that helps!
Rank,NameMale,NameFemale
1,Oliver ,Amelia
2,Jack ,Olivia
3,Harry ,Emily
4,George ,Isla
5,Jacob ,Ava
6,Charlie ,Ella
7,Noah ,Jessica
8,William ,Isabella
9,Thomas ,Mia
10,Oscar ,Poppy