Previous Slide 2 Error : Code Won't Work


#1



Hi everyone! I'm stuck in this exercise, as linked below. I've thoroughly looked through the code, and so far couldn't find what else I need to fix it, and would love some help please. I also only had to add lines 34 to 36 in this exercise as per instructions:

Inside the click event handler for '.arrow-prev', write an if statement to handle this case:
- After creating the variables currentSlide and prevSlide, write an if statement that checks if prevSlide.length == 0.
- If it is, set prevSlide equal to the last slide using $('.slide').last();
- Try it out! In the web page to the right, click the previous arrow and see what happens!

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


Error messages are as follows:
- Uncaught SyntaxError: Invalid or unexpected token
- Oops, try again. Remember to fade out the current slide and remove the 'active-slide' class.


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

$(document).ready(main);

Thank you very much!


#2

Hi @samwiththej,

Take a close look at line 22 of your code :slight_smile:


#3

Thank you so much! :blush:


#4

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