Lesson 9: Previous slide 2


#1

I keep getting the error message:
Oops, try again. Remember to fade out the current slide and remove the 'active-slide' class.

I'm not sure why. It all worked until this point.

I also have this error on the right:
Uncaught SyntaxError: Unexpected end of input

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();
    }

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


#2

Compare the code in arrow-next to that in arrow-prev. Note the differences and add in the missing code.


#3

The code in arrow-prev is identical to the one in the hint.


#4

Use the other segment of code for an example. Ignore the hint. It should be readily apparent what code you are missing.


#5

This is the instructions forthis part of the lesson:

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!

It says nothing about adding in that extra code.


#6

Ho just go on the previous lesson (lesson 8: previous slide 1) and read again The instruction


#7

Addressing the syntax error... Add a closing curly brace at the end of the main function. I just tracked down the lesson and passed with your code.


#9

Now I have this code which still gives me the same error:

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();
    }

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

$(document).ready(main);

I also now have this error on the right:

Uncaught SyntaxError: missing ) after argument list


#10

There is still a missing closing brace (should be just above $(document).ready(main).

This code,

  $('.dropdown-toggle').click(function() {
    $('.dropdown-menu').toggle();
   }
  });

has a stray curly brace (second last line).


#11

I found the stray curly brace but I'm not sure what you mean by the closing brace above the very last line.


#12

The main() function is not closed.

var main = function() {

};

#14

A post was split to a new topic: Remember to fade out the current slide


#15

A post was split to a new topic: What is wrong with this code


#17