Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript jQuery Basics (2014) Creating a Simple Drawing Application Perform: Part 1

Henrik Christensen
seal-mask
.a{fill-rule:evenodd;}techdegree
Henrik Christensen
Python Web Development Techdegree Student 38,322 Points

Why does my code not work?

Hello,

I've written the same code as the teacher but when I preview it nothing happens, but it works perfect when the teacher preview the same piece of code.

//Problem: No user interaction causes no change to application
//Solution: When user interacts cause changes appropriately

var color = $(".selected").css("background-color");

//When clicking on control list items
$(".controls li").click(function() {
  //Deselect sibling elements
  $(this).siblings().removeClass("selected");

  //Select clicked element
  $(this).addClass("selected");

  //Cache current color
  color = $(this).css("background-color")
});

4 Answers

Markus Ylisiurunen
Markus Ylisiurunen
15,034 Points

Hi!

It seems to be almost right. You've forgotten a semicolon from the last line inside the function. Other than that it looks like it's fine.

Hope it helps.

Markus Ylisiurunen
Markus Ylisiurunen
15,034 Points

Okay then, seems weird. Can you put all your code (HTML and JS) to CodePen for me to see. My Treehouse account is currently paused so I can't see the video.

Markus Ylisiurunen
Markus Ylisiurunen
15,034 Points

Classic :) Well one thing that might be wrong is that workspaces use https and you're trying to load jQuery over http. Your browser might block you from doing that. You could try changing http to https for the jQuery script tag.

If that doesn't work try checking your console (F12 in Chrome) if it shows you any errors. And if it doesn't show you any errors try typing $ in the console and see what it says.

Henrik Christensen
seal-mask
.a{fill-rule:evenodd;}techdegree
Henrik Christensen
Python Web Development Techdegree Student 38,322 Points

I don't know what happend - I changed it to https and then back to http and now it's working perfect (same code as before)..

Thank you very fun for all your input and help :-D

Markus Ylisiurunen
Markus Ylisiurunen
15,034 Points

Glad you got it working. Sometimes those kinds of errors are the real pain.

Christopher Mlalazi
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Christopher Mlalazi
Front End Web Development Techdegree Graduate 17,305 Points

Happy I spotted the missing semi colon too in the last line before I went to the comments. I am teaching myself to read code and spot such things. Great you got it working too Henrik! Cheers!