0

Noob coder in need of assistance.

In a nutshell I’m working on an offspring generator. I have 2 Dropdown menus named “Mother” and “Father” with a few choices a piece. I also have a list of variables that contain 2 choices a piece (these represent the possible genes that could be passed from the parent) (the variables should be tied to the drop down selections) What I want to happen is when a “Mother” and “Father” are selected and a button is pressed a random choice (1of2) is selected from a variable (tied to the mother selection) and a random choice (1of2) is selected from a variable (tied to the father selection) these 2 variables are then combined and displayed (Showing the Offspring) I figured out how to choose a random option within the variable but I can’t figure out how to call the correct variable based off the user selection in the drop down. Any guidance would be much appreciated. Thanks.

15th Jun 2018, 5:11 PM
Daniel R. Pope
Daniel R. Pope - avatar
2 Respostas
+ 1
Hey! So if I understand what you are saying correctly when the parents are selected in this drop down menu and the button is pressed you want one of the attributes from the father and mother chosen at random and displayed as offspring. Im assuming you are using javascript. What I would do is is something like the code I am posting below. Essentially what I did is I assigned each father with an array of attributes and when I click on the button the JS looks at the value of the option, goes to the corresponding key in the genePool, assigns the value at a random index between 1 and 0 to a variable for both mother and father, puts both those attributes into a new array of attributes for the offspring, and then adds it to the appropriate li tag in the list. https://code.sololearn.com/WDhEv8dAZXq6
16th Jun 2018, 1:50 AM
Haon1919
Haon1919 - avatar
+ 1
very similar yes. thank you. i can use this as a base to work from.
16th Jun 2018, 2:41 AM
Daniel R. Pope
Daniel R. Pope - avatar