I have a javascript array, mediaSizes as follows: ['xs','md','lg'].
I'm using a variable media to refer to the specific index in the array. So media can either be 0, 1, or 2. So mediaSizes[media] should either output xs, md, or lg.
I have up and down arrows for user to cycle through this array. However, when the user clicks the up arrow, and the media value is 2, I want the user to cycle back down to xs. Similarly, if the user presses the down arrow on xs I want them to cycle through to large.
I have the following if else statement, but it doesn't seem to be working:
var mediaSizes = ['xs','md','lg'];
var media = 0;
$scope.mediaDisplay = mediaSizes[media];
$scope.changeMedia = function(direction) {
if (media > 2 || media < 0) {
media = 0;
} else {
if (direction == 'up') {
media ++;
$scope.mediaDisplay = mediaSizes[media];
} else {
media --;
$scope.mediaDisplay = mediaSizes[media];
}
}
}
Right now, I settled for setting the media value to 0 for the sake of getting it to work. There has to be an easier way to cycle through 0, 1, 2...
var mediaDisplaybe$scope.mediaDisplay(or justmediaDisplay, depending on what$scopeis?) Otherwise, the value ofmediaDisplayis scoped to the changeMedia function...var mediaDisplayisn't actually changing anything.