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

help with radio buttons

JavaScript

//Color Mixer x
let div24 = document.querySelector('div#pro24');
let color1 = document.forms('radio[name="firstColor"]');
let color2 = document.forms('radio[name="secoundColor"]');
if(color1[0].checked && color2[0].checked){
    div24.style.bakcgroundColor = "red";
}

HTML

            <div class="all" id="pro24"><!-- Color Mixer -->
                <h1>Color Mixer</h1>
                <form name="firstColor">
                    <p>First Color</p>
                    <input type="radio" name="firstColor" value="red1" checked> Red<br>
                    <input type="radio" name="firstColor" value="blue1"> Blue<br>
                    <input type="radio" name="firstColor" value="yellow1"> Yellow  
                </form>
                <form name="secoundColor">
                    <p>Secound Color</p>
                    <input type="radio" name="secoundColor" value="red2" checked> Red<br>
                    <input type="radio" name="secoundColor" value="blue2"> Blue<br>
                    <input type="radio" name="secoundColor" value="yellow2"> Yellow  
                </form>
            </div>

I am not sure how to call the radio button checked property.

2 Answers

Hello,

If I understood well, you need to check if the radio button has the attribute "Checked" in your if statement right?

If that's the problem, you should be able to achieve this like so:

if (color1[0].hasAttribute("Checked");

I'm not sure about this, but please try it out and tell me if it worked.

Thank you for responding but yeah that did not do the trick:(