I have this code that first reads which position of a checkbox is checked and then executes several ifs. Then I thought I could make the code smaller if I used switch/case, while also portfolio-ing the command for later uses. The command was like this:
if (fsex[0].checked {
gender = 'man'
if (age >= 0 && age <= 10) {
img.setAttribute('src', 'male-baby.png')
} else if
I tried using switch by changing the below "gender" line to something like this:
switch (age) {
case (age >=0 && age <= 10):
img.setAttribute('src', 'male-baby.png')
break
case ...etc
This didn't work.
Then I tried with case >=0
, which then the VSCode immediatly returns a sintax error "expression expected.
Is there a way I can use switch/case to this one? Or I should just stick with several if/ else ifs?