Most efficient coding style for forms with multipl

2019-09-14 16:02发布

问题:

I am have a form that look something like this:

I want the input.variable I am going to throw into localStorage based on the number of boxes filled out and the radio boxes checked. It would apply as follows:

-Radio Buttons-
One Name Typed in:
na : Name
F: Name and friend
F+ Name and friends

Two Names typed in:
na: Name and Name
F: Name, Name and friend
F+: Name, Name and friends

Three Names typed in:
na: Name, Name and Name
F: Name, Name Name and friend
F+: Name, Name, Name and friends

Four Names typed in:
na: Name, Name, Name and Name
F: Name, Name, Name, Name and friend
F+: Name, Name, Name, Name and friends

What would be the best way to approach this? I am trying to think of the most efficient way to write this beyond multiple if/then/else statements.

Thanks

回答1:

Ok, since my comment seems to have pointed you in the right direction, I'm pasting it here as an answer:

if you want a clean way to arrange data, use an object literal. If you're dealing with a wash of if elseif elseif statements, consider using a switch, if all conditionals check a different value, just use switch (true)