This forum is now read-only. Please use our new forums! Go to forums

0 points
Submitted by sunoy14
almost 9 years

why nextDot.length === 0?

Lesson: Next Dot 2. Exercise 7/12 Interactive website flipboard. Why are we checking if(nextDot.length === 0) ?

Why are we using .length?

Why are we checking it === 0 ?

If , if(nextDot.length === 0) is true, wouldn’t that just mean the first item of the dot class? like variable[0] in javascript and other language arrays? How are they different?

Thanks.

Answer 55355ef693767641da000292

0 votes

Permalink

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');
});

$('.arrow-prev').click(function(){
    var currentSlide = $('.active-slide');
    var prevSlide = currentSlide.prev();
    var currentDot = $('.active-dot');
    var prevDot = currentDot.prev();
    
    if(prevSlide.length == 0) {
        prevSlide = $('.slide').last(); 
        prevDot = $('.dot').last();
    }
    
    currentSlide.fadeOut(600).removeClass('active-slide');
    prevSlide.fadeIn(600).addClass('active-slide');
    
    currentDot.removeClass('active-dot');
    prevDot.addClass('active-dot');
});

};

$(document).ready(main);

points
almost 9 years