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

Why does this not do anything?

I used the following code and when I clicked the button it did not run. Why is this?

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-08">
        <link rel="stylesheet" type="text/css" href="main.css">
    </head>
    <body>
        <button type="button" onClick="myFunction()">Run</button>
        <script type="text/javascript">
            function myFunction() {
                var a=2;
                var b=2;
                var c=4;
                if a+b=c {
                    document.write("True");
                } else {
                    document.write("False");
                }
            }
        </script>
    </body>
</html>

1 Answer

your if-statement has some syntax errors. The condition that you are checking needs to be inside of a parenthesis. Like this:

if (a+b==c) {
...
}

Also, as you can see from this code, I have added another = sign in that condition. A single = sign serves the purpose of assigning a value , usually to a variable just like you did at the start of your code. Double == however means "equals" and that's what you need to use when checking if a condition is met or not.