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


Harshavardhan Gangavarapu
Harshavardhan Gangavarapu
13,727 Points

Error in code. help me

<!DOCTYPE html>
    <title>JavaScript and the DOM</title>
    <link rel="stylesheet" href="css/style.css">
    <h1 id="myHeading">JavaScript and the DOM</h1>
    <p>Making a web page interactive</p>
    <input type="text" id="myTextInput">
    <input type = "text" id = "myColorInput">
    <button id="myButton">Change color</button>
    <button id = "backgroundColor">Change background color</button>
    <script src="app.js"></script>
const myHeading = document.getElementById('myHeading');
const myTextInput = document.getElementById('myTextInput');
const myButton = document.getElementById('myButton');
const backgroundColor = document.getElementById('backgroundColor');
myButton.addEventListener('click', () => {
                            myHeading.style.color = myTextInput.value;
backgroundColor.addEventListener('click', () => {
                                  myHeading.style.background-color = myColorInput.value;

Error: Uncaught ReferenceError: Invalid left-hand side in assignment

1 Answer

Emmanuel C
Emmanuel C
10,636 Points


myHeading.style.background-color //doesnt exist
myHeading.style.backgroundColor //does exist

That error means that the compiler thinks youre trying to assign whats on the left side of the '=' operator into the right side variable.