Created
May 21, 2014 17:39
-
-
Save TylerFisher/1550c351b7ebc5ca98b8 to your computer and use it in GitHub Desktop.
An example of good code structure for Unclass
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// all variables I will use | |
var photosArray; | |
var photosArrayCounter; | |
var $visiblePhoto; | |
// all functions | |
var changePhoto = function() { | |
if ($(this).hasClass('next') && photosArrayCounter < photosArray.length) { | |
photosArrayCounter++; | |
} | |
else if ($(this).hasClass('prev') && photosArrayCounter > 0) { | |
photosArrayCounter--; | |
} | |
$visiblePhoto.attr('src', photosArray[photosArrayCounter]); | |
} | |
// what should happen when the page loads | |
$(document).ready(function() { | |
// declare variables | |
photosArray = ['img1.jpg', 'img2.jpg', 'img3.jpg', 'img4.jpg']; | |
photosArrayCounter = 0; | |
$visiblePhoto = $('.photo'); | |
// attach event handlers | |
$('.next').click(changePhoto); | |
$('.prev').click(changePhoto); | |
// call any functions that need to run on page load | |
// we don't have any | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment