Skip to content
Advertisement

How to determine whether a switch case was chosen?

I’ve got a project that I am working on and it requires I have an array with a set size of 5. I then need to gather data from 4 different cases, and store them 5 times. (One of the cases can be used multiple times, case gets specified by user input). Here is what I have tried:

JavaScript

I planned on replacing the last Switch(count) with something else, but am not sure how to go about it. The issue I have, is that no matter what I input, that Switch(count) will always iterate to the next one and does not care what I chose. So if I chose the employeeType of 1, then chose employee type of 3, it would ask me the info for type 3, but display all the info for type 2 (leading to blank results).

JavaScript

As shown above, the output displays a Salaried, Hourly, Commission, BasePlus, then Salaried employee, when I actually input a Salaried, then Salaried again.

Advertisement

Answer

If I understand correctly, this should work:

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement