+ 4
Switch with array and function
how can I create a function that find if each value in the array are divisible by 2 or 3 or 4 or 5. (using switch) https://code.sololearn.com/c62wZ1V1jNXy/?ref=app
9 Respuestas
+ 2
switch statements requires constants in their casing however there is a work around by using a for loops and pre checking if it divisable by a index and use that index in the casing like my code below
https://code.sololearn.com/cMBd435JMYQ5/?ref=app
+ 3
Thanks guys, I solved the problem and modified the code
+ 2
I didnt see functions part haha but you just copy paste that and return how you desire depeding on the divisable.
+ 2
Explain more about the problem
+ 1
what part is not working?
+ 1
it is easier if you are allowed to use libraries, the code becomes more flexible too. switch case is not necessary here and even makes the code rigid and hard to modify later on.
https://code.sololearn.com/ctH6376oNB95/?ref=app
0
is switch really necessary or is it part of a lesson on switch usage?
https://code.sololearn.com/c7qHP22nbLSc/?ref=app
0
not necessary but yes it is part of a lesson on switch usage
Bob_Li
0
Bob_Li why it is not work in this code ?