7.2 Next dot 2


#1


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


The dot indicator doesn't roll-over from the last one back to the first.

This is the error message I get: '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.'


This is the piece of code where the problem might be, but I can't seem to notice it:

if(nextSlide.length == 0) {
        nextSlide = $('.slide').first();
        nextDot = $('.dot').first();
    }



This is the full 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);


#2

your code should be like

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();
    }
    
    
    currentDot.removeClass('active-dot');
    nextDot.addClass('active-dot');
  
    
    currentSlide.fadeOut(600).removeClass('active-slide');
    nextSlide.fadeIn(600).addClass('active-slide');
    });
};


$(document).ready(main);

i hope you'll understand.feel free to ask any question :slight_smile:


#3

Thank you so much! It worked.


#4

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