Switch conditional statements
Brandon helped me out with this one.
Switch statements clean up your code when you’re checking if a variable matches a value. Say if you’re looking to check if the variable direction is valid.
Bad way
if ( direction === 'north' || direction === 'south' || direction === 'east' || direction === 'west' ) {
console.log('valid direction: ' + direction);
} else {
console.log('invalid direction');
}
Better way with a switch statement
switch ( direction ) {
case 'north' : case 'south' : case 'east' : case 'west' :
console.log('valid direction: ' + direction);
break;
default :
console.log('invalid direction');
}