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 JavaScript Functions Create Reusable Code with Functions Using Multiple return Statements

Why is my alert box not popping up?

function isFieldEmpty() {
    const field = document.querySelector('#info');
    if (field.value ==== '') {
        return true;
    } else {
        return false;
    }
}

const fieldTest = isFieldEmpty();

if (fieldTest === true) {
    alert("Please provide your information.");
}

Here is my HTML code:

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>JavaScript Functions</title>
    <link href="css/style.css" rel="stylesheet"> 
  </head>
  <body>
    <main>
      <input type="text" id="info">
    </main>
    <script src="js/multiple.returns.js"></script>  
  </body>
</html>

2 Answers

Figured it out!

File name was incorrect. I fixed it to read

<script src="js/multiple-returns.js"></script>
Mark Sebeck
Mark Sebeck
Treehouse Moderator 37,905 Points

Great Job! I changed your comment to an answer and made it the best answer. Keep at it!

boi
boi
14,242 Points

You have four equal signs on line 3.

function isFieldEmpty() {
    const field = document.querySelector('#info');
    if (field.value ==== '') {     👈
        return true;
    } else {
        return false;
    }
}

No error for that?