Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript JavaScript Loops, Arrays and Objects Tracking Multiple Items with Arrays Using For Loops with Arrays

Trying to practice using refactor, need insight please

practice project

$("#img .photo-1").click(function(){
  $("#img .photo-1").fadeOut(500).hide()
  $("#img .photo-2").fadeIn(300).show()
  $("#img .photo-2").click(function(){
    $("#img .photo-2").fadeOut(500).hide()
    $("#img .photo-3").fadeIn(300).show()
     $("#img .photo-3").click(function(){
      $("#img .photo-3").fadeOut(500).hide()
      $("#img .photo-4").fadeIn(300).show()
       $("#img .photo-4").click(function(){
        $("#img .photo-4").fadeOut(500).hide()
        $("#img .photo-1").fadeIn(300).show()




the code works but I know it can be more concise, nothing I've tried works

2 Answers

I looked at that, thank you. I think it's using classes as a way to show and hide w/out repeating all the selectors? Is that a general idea there? Or are you saying don't ask those kind of questions on this forum...

anil rahman
anil rahman
7,786 Points

No, i just merely linked you a similar topic example, that you may be able to change in some way to adapt it to your own situation. I haven't done enough JQuery to say what is the right way and what is wrong when it comes to your problem.

Thanks Anil.