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

Russ Tuttle
seal-mask
.a{fill-rule:evenodd;}techdegree
Russ Tuttle
Full Stack JavaScript Techdegree Student 8,909 Points

Project 3- T-Shirt Info Section

Hi, I'm having a bit of difficulty with the T-Shirt Section of Project 3. I am trying to test my variables for value and attribute. When I log value I get the results printed but for attribute I always get "null" returned. How can I get the attribute variable to print the color options in the console.log?

//T-Shirt info section*****
const color = document.getElementById("color");
const design = document.getElementById("design");
color.disabled = true;

design.addEventListener("change", () => {
  color.disabled = false;
  for (let i = 0; i <= color.children.length; i++) {
    const value = event.target.value;
    const attribute = color.getAttribute("data-theme");

    console.log(value)
    console.log(attribute)

  }
});
            <div id="shirt-designs" class="shirt-designs">
              <label for="design">Design:</label>
              <select id="design" name="user-design">
                <option hidden>Select Theme</option>
                <option value="js puns">Theme - JS Puns</option>
                <option value="heart js">Theme - I &#9829; JS</option>
              </select>
            </div>

            <div id="shirt-colors" class="shirt-colors">
              <label for="color">Color:</label>
              <select id="color">
                <option selected hidden>Select a design theme above</option>
                <option data-theme="js puns" value="cornflowerblue">Cornflower Blue (JS Puns shirt only)</option>
                <option data-theme="js puns" value="darkslategrey">Dark Slate Grey (JS Puns shirt only)</option> 
                <option data-theme="js puns" value="gold">Gold (JS Puns shirt only)</option>
                <option data-theme="heart js" value="tomato">Tomato (I &#9829; JS shirt only)</option>
                <option data-theme="heart js" value="steelblue">Steel Blue (I &#9829; JS shirt only)</option> 
                <option data-theme="heart js" value="dimgrey">Dim Grey (I &#9829; JS shirt only)</option> 
              </select>
            </div>
          </div>
        </fieldset>
      </div>    

1 Answer

<select id="color"> does not have a value for a data-theme attribute. Try changing const attribute = color.getAttribute("data-theme"); to const attribute = color.children[i].getAttribute("data-theme"); and changing i <= color.children.length to i < color.children.length