+ 1

Give a same family name each family HELP!!

I want to give a same family name each family but it didn't work pretty well. The parent's name are same and different each family but the child's name not following the parent's name. I wanna know if theres some way to fix it. //part one msg("My name is " + this.name + ".") msg("My mother is " + randomName() + " " + randN + " (Age " + randomInt(20, 60) + ").") msg("My father is " + randomName() + " " + randN + " (Age " + randomInt(20, 60) + ").") msg("<br>") //second part var numberOfPersons = 10 var persons = [] for(var i = 0; i < numberOfPersons; i++){ var randN = randomName() var name = `${randomName()} ${randN}` var age = 0 var energy = randomInt(50, 200) var money = 0 var iq = randomInt(50, 100) var health = randomInt(50, 200) var relation = 0 persons.push(new Person(name, age, energy, money, iq, health, relation)) } https://code.sololearn.com/WmpsZo2vX64k/?ref=app

3rd Sep 2020, 4:01 AM
Tri Satria [NEW]
Tri Satria [NEW] - avatar
7 Antworten
+ 3
Make a hash map in such a case!
3rd Sep 2020, 4:09 AM
Namit Jain
Namit Jain - avatar
+ 3
You can implement in the way you want! Here is how you can extract the same details for the same name! You can put the child's name and the respective parent's name in it! https://code.sololearn.com/WbkkS3OzZf7p/?ref=app
3rd Sep 2020, 4:30 AM
Namit Jain
Namit Jain - avatar
+ 3
Try this in the Person function constructor this.surName = name.split(" ")[1] and replace randN with this.surName; https://code.sololearn.com/WHS5q95ay40i/#js see line 79
3rd Sep 2020, 6:58 AM
ODLNT
ODLNT - avatar
+ 2
Can you implement it in the code
3rd Sep 2020, 4:14 AM
Tri Satria [NEW]
Tri Satria [NEW] - avatar
+ 1
You can search about hashmap on google and it is not very hard to implement it! Since I have not made this code so I am not sure if your problem is fixed or not! For the same child name it will show the respective parents' names only! See this: https://code.sololearn.com/W0FZX6HFL0pa/?ref=app
3rd Sep 2020, 6:04 AM
Namit Jain
Namit Jain - avatar
+ 1
But it didnt return the same child and parents lastname. i want to equalize the name of parents and childs but different each family
3rd Sep 2020, 6:22 AM
Tri Satria [NEW]
Tri Satria [NEW] - avatar
0
I dont get it, could you try hashmap on my codes?
3rd Sep 2020, 5:52 AM
Tri Satria [NEW]
Tri Satria [NEW] - avatar