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

CSS CSS Basics (2014) Enhancing the Design With CSS Gradients

background-image: linear-gradient(red, blue); is not working for me when I target .main-header. Why?

background-image: linear-gradient(red, blue); is not working for me when I target .main-header. Why?

style.css
/* Complete the challenge by writing CSS below */
.main-header{
    color: white;  
    background-image: linear-gradient(green, yellow);
}
index.html
<!DOCTYPE html>
<html>
  <head>
    <title>Lake Tahoe</title>
    <link rel="stylesheet" href="page.css">
    <link rel="stylesheet" href="style.css">
  </head>
  <body> 
    <header id="top" class="main-header">
      <span class="title">Journey Through the Sierra Nevada Mountains</span>
      <h1 class="main-heading">Lake Tahoe, California</h1>
    </header>

        <div class="primary-content">
            <p class="intro">
                Lake Tahoe is one of the most breathtaking attractions located in California. It's home to a number of ski resorts, summer outdoor recreation, and tourist attractions. Snow and skiing are a significant part of the area's reputation.
            </p>
            <a class="callout" href="#more">Find out more</a>
        </div><!-- End .primary-content -->
  </body>
</html>

8 Answers

is there something wrong with this syntax?

if(answer.length < 3){
document.querySelector("main").innerHTML = story1; } else(answer.length > 2){ document.querySelector("main").innerHTML = story2; }

Gergely Bocz
Gergely Bocz
14,244 Points

Hi Glenn!

What's the problem? You mean you can't get over the challenge, because it throws an error? The challenge want you to use steelblue and darkslateblue values for the linear-gradient function and there is no need for the color property.

If this wasn't your question, can you elaborate on it a bit?

Thank you so much. Whatever bug was there is gone now.

Mr. Bocz I'm so disheartened. I believe most of the problems that I have are due to the software or operating system I'm using. Couple that with the fact that I've done the courses with almost zero practice, it now appears that I've learned nothing at all. It's like I know all the ingredients to making a cake but have forgotten the proper order of their mixing procedure. I know this too shall pass, but I'm really needing a human right now. Just needing someone to talk to who understands.

Gergely Bocz
Gergely Bocz
14,244 Points

Glenn, i know how you feel. I have been coding for a couple of years now, with - occasionally multiple month - long hiatues, and i was relying mostly on the methods and practices that i was taught in courses such as this. But recently i started having my own projects, and i figured out that programming in reality is completely different from programming through well laid out examples. Doing your own projects, you start to realize that there are so many decisions you have to make, and that ultimately it's up to you, to make your own path.

I believe that programming is about problem solving. Which means that you have to find what's problematic in that case for you, what that problem means to you. Nothing can teach you as much, as starting your own project, taking responsibility for your decisions and trying to find answers to your questions that naturally emerge there. It really teaches a lot about order and mixing procedure!

Therefore i suggest you, to start working on something on your own. Ultimately courses and other learning materials really are just guides to help you on your path, but you have to find that path on your own. Try asking more and more questions from yourself, and if the answer is elusive, turn to communities such as this to help you find a solution!

If you are disheartened now because of recent failures, take a break, give yourself time to calm down, and when you are ready, dive into something challenging with renewed strength!

And as far as softwares are concerned, my advice is, just try to be on the same page with the communities that you are a part of, so that they can help you with such issues.

I wish you the best, good luck! :)

Gergely Bocz
Gergely Bocz
14,244 Points

Hi Glenn!

I'm just curious, how are you doing?

Much better, I'm more comfortable with Javascript as I did get an A in c++ my freshman year 26 years ago lol. I have found that the tutorial is a little shaky in areas and as you know the frustration of coding takes a little getting used to. My old roommate from an engineering internship back in the day is now the owner and CEO of a software company called Riffyn. He was a professor of biomedical engineering at Boston University and programming was something of a side hobby until he used it as a solution for a biochemical company he worked for and turned the solution into a global enterprise. I'm here playing catch up because he owes me a job for being his friend and I want it.

Gergely Bocz
Gergely Bocz
14,244 Points

Oh, i see. I'm glad to hear you are doing better! :) Good luck with programming and preparing for that job!

Whenever you need some help, you know where to find me!

THANK YOU, SO MUCH!!

Gergely Bocz
Gergely Bocz
14,244 Points

Yes there are a couple of problems.

First of all, whenever you use document.querySelector, you have to be specific with your selector: If you want to select something with an id, you have to use "#", if you want to select a class, you have to use ".". In this case i assume that "main" is not an html tag, so something has to go before that, an "#" if it's an id, and a "." if it's a class. Basically it works just like css selectors.

Second, whenever you want to specify the condition inside the else parentheses, you have to use else if instead of "else".

These two are the main issues, the rest of my writing are just suggestions.

And i also have another question related to the story1 and story2 variables: What do they look like? Because if they are strings, like "Once upon a time, there was a...", then you should use the .textContent method instead of ".innerHTML", as .innerHTML can leave you vulnerable to certain hacking attacks (though these are mostly handled by big libraries and frameworks). The point is, you should only use .innerHTML, if you have to, and then you also have to make sure that you use it safely. You must use .innerHTML, if they contain html tags and look something like this: "<h1>Story title</h1> <p>Some text</p>", then you have to use .innerHTML.

So assuming, that "main" is a class, and story1 and story2 are strings, your code should look something like this:

if(answer.length < 3){
 document.querySelector(".main").textContent = story1;
}else if(answer.length > 2){
 document.querySelector(".main").textContent = story2;
}

Also if you want it to write it in a more condense way, you could do something like this:

let mainContent = document.querySelector(".main");
mainContent.textContent = answer.length < 3 ? story1 : story2; 

You can read more about this operator here

Also i think, that since the original question of this post has been answered, we should close this post, and whenever you have a question, create a new post, and ask your question there. That way more people can see it and help you! :)