Previous dot 2 Been Stuck For Too Long :(


#1

<PLEASE USE THE FOLLOWING TEMPLATE TO HELP YOU CREATE A GREAT POST!>

I am exhausted from staring at this, I can’t see anything wrong with it. Please help

<Below this line, add a link to the EXACT exercise that you are stuck at.>
https://www.codecademy.com/en/courses/web-beginner-en-seyrq/0/11?content_from=make-an-interactive-website%3Ajquery-effects#
<In what way does your code behave incorrectly? Include ALL error messages.>
Oops, try again. Remember to add ‘.active-dot’ to the previous dot



var main = function (){
    $('.dropdown-toggle').click(function(){
        $('.dropdown-menu').toggle();
    });
    
    $('.arrow-next').click(function(){
        var currentSlide = $('.active-slide');
        var nextSlide = currentSlide.next();
        if (nextSlide.length === 0) {
            nextSlide = $('.slide').first();
        }
            
        currentSlide.fadeOut(600).removeClass('active-slide');
        nextSlide.fadeIn(600).addClass('active-slide');
        
        var currentDot = $('.active-dot');
        var nextDot = currentDot.next();
        if (nextDot.length === 0) {
            nextDot = $('.dot').first();
        }
        
        currentDot.removeClass('active-dot');
        nextDot.addClass('active-dot');
    });
    
    $('.arrow-prev').click(function(){
        var currentSlide = $('.active-slide');
        var prevSlide = currentSlide.prev();
        if (prevSlide.length === 0) {
            prevSlide = $('.slide').last();
            prevDot = $('.dot').last();
        }
        
        currentSlide.fadeOut(600).removeClass('active-slide');
        prevSlide.fadeIn(600).addClass('active-slide');
        
        var currentDot = $('.active-dot');
        var prevDot = currentDot.prev();
        
        currentDot.removeClass('active-dot');
        prevDot.addClass('active-dot');
    });
};

$(document).ready(main);


#2

Hi @jaosin,

You need to create the currentDot and prevDot variables before your if statement, since that modifies what the prevDot variable would be before it’s gotten created.


#3

Yep, that worked! Thank you so much!


#4

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