+ 1
How i can use?
I don't understand how use it
5 Réponses
+ 7
switch(variable){
case variable: statement ;
break;
case variable: statement ;
break;
default: statement ;
}
when the variable is equal, it execute the expression which have the case
+ 1
Thank you, can you give me an example?
+ 1
it basically eliminates the need to write multiple if-else if statements e.g.
let say you had a basket with three colored balls in it(red, green and blue)
switch(ballCol){
case ‘red’:
alert(‘red ball selected’)
break;
case ‘green’:
alert(‘green ball selected’)
break;
case ‘blue’:
alert(‘blue ball selected’);
break;
}
+ 1
For examples and learning Switch Case you can use search bar in SoloLearn and can learn switch in multiple languages.