nextDot not working correctly?


#1

I'm working on how to make an interactive website, I'm on 7/12, and I had to make the dots below a carousel, but the if statement isn't working the way it should?

Here's my code:

var main = function() {
// Toggles dropdown menu.
$('.dropdown-toggle').click(function() {
$('.dropdown-menu').toggle();
});
// "Next Arrow" function
$('.arrow-next').click(function() {
var currentSlide = $('.active-slide');
var nextSlide = currentSlide.next();

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

currentSlide.fadeOut(600).removeClass('active-slide');
nextSlide.fadeIn(600).addClass('active-slide');

// Animated dots for the carousel.
var currentDot = $('.active-dot');
var nextDot = currentDot.next();

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

$(document).ready(main);


#2

Hi Dane,

You can't work with a variable before defining it. These two lines:

belong above the if statement checking if nextSlide.length === 0.


#3

Yeah I noticed that a few minutes ago, but now I'm having problems with the next step lol. I'll make a new post though.