7.Next dot 2: Next dot not wrapping back to first dot


#1


7.Next dot 2


https://www.codecademy.com/en/courses/web-beginner-en-seyrq/0/7?content_from=make-an-interactive-website%3Ajquery-effects#

I'm trying to get the dot to wrap back to the first dot. I've looked at the hint, and i'm pretty sure that my code is identical to it. It comes up with an error message that says:

Oops, try again. When on the last slide, it looks like next arrow isn't wrapping back to the first dot. Look back at the instructions and check the code inside the if statement.

My code:

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();
       
        currentDot.removeClass('active-dot');
        nextDot.addClass('active-dot');
       
       if(nextSlide.length == 0) {
            nextSlide = $('.slide').first();  
            nextDot = $('.dot').first();
       }
       
       currentSlide.fadeOut(600).removeClass("active-slide");
       nextSlide.fadeIn(600).addClass('active-slide');
    });
};
$(document).ready(main);


Thanks


#2

HI this part of the code should be at then end (or just after the if statement ) inside the $('.arrow-next').click(function(){ ... )};

currentDot.removeClass('active-dot');
nextDot.addClass('active-dot');

because your are using it in the if statement so if you remove it the if statement won't find it.


#3

Ohh! Now I get it! Thanks so much! :slight_smile:


#5

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.