Previous Dot 2


#1

I keep getting Oops, try again. Remember to remove '.active-dot' from the current dot.

Where am I going wrong?

`var main = function () {
$(".dropdown-toggle").click(function() {
$(".dropdown-menu").toggle();
});

$('.arrow-next').click(function () {
   var currentSlide = $('.active-slide');
   var nextSlide = currentSlide.next();
   currentSlide.fadeOut(600).removeClass('active-slide');
   nextSlide.fadeIn(600).addClass('active-slide');

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

   var currentDot = $('.active-dot');
   var nextDot = currentDot.next();

   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

@_matts1,
Do not forget to use a closing-curly-bracket-} to close the =main= FUNCTION-BODY

Have a read
https://www.codecademy.com/forum_questions/5615308ab62548021c0000e4


#3

Hi @_matts1

I had this problem,
You need to make sure all your variables are listed together. I originally had it structured the same as you, however once I moved them together it worked . I've pasted the .arrow-prev function below so you can see what I mean.

My understanding of why this works is that right now in your code you have an 'if' statement attempting to effect variable that you are yet to define, so at the moment, it runs the "if" statement before you've told it what 'prevDot' actually is. I'm like 90% sure that's why it works when they're together.
Hope this helps :slightly_smiling:

$('.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');
   


    
});

#4

This solved my problem :slightly_smiling: Thank you


#5

I discovered this after I posted this but it didn't completely solve it but thanks :slightly_smiling: