javascript - Why do I have to check for length === 0 to restart the slides? -


i'm following codecademy "make interactive website" course. don't have error, had question don't understand: if-statement used in slide thing thing thing.

if (nextslide.length === 0) {             nextslide = $('.slide').first();             nextdot = $('.dot').first();         }; 

this if-statement after last slide go first slide. why nextslide.length === 0?

jquery:

var main = function() {     $('.dropdown-toggle').click(function() {         $('.dropdown-menu').toggle();     });     $('.arrow-next').click(function() {         var currentslide = $('.active-slide');         var nextslide = currentslide.next();          var currentdot = $('.active-dot');         var nextdot = currentdot.next();          if (nextslide.length === 0) {             nextslide = $('.slide').first();             nextdot = $('.dot').first();         };          currentslide.fadeout(600).removeclass('active-slide');         nextslide.fadein(600).addclass('active-slide');          currentdot.removeclass('active-dot');         nextdot.addclass('active-dot');     }); };  $(document).ready(main); 

the if statement there check if there slide after current slide or if should revert first slide.

nextslide.length return number represent if next slide exists, else return 0.

.length api docs: here


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -