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

Tracy Excell
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Tracy Excell
Front End Web Development Techdegree Graduate 15,333 Points

What am I missing in my Javascript code?

I am trying to make javascript code work to search for a date, it it is the same then an alert box would pop up. Mine is not working 100%. Can anyone tell me where I am going wrong?

```<!DOCTYPE html> <html lang ="en">

<head>
    <meta charset="utf-8">
        <title>HTML Video Assignment</title>
            <meta name="viewport" content="width=device-width" initial-scale=1>

    <link href="https://fonts.googleapis.com/css?family=Prociono" rel="stylesheet">
    <link rel="stylesheet" href="normalize.css"> 
    <link rel="stylesheet" href="main.css">
</head>

    <body>

       <table>
          <tr>
            <th>Name</th>
            <th>Registration Due</th>
          </tr>
          <tr>
            <td>Grant</td>
            <td id="date">020319</td>
          </tr>
    </table>



     <script src="http://code.jquery.com/jquery-1.12.0.min.js"></script>
     <script src="code.js"></script>
    </body>
    </html>

``` prompt("Please enter todays date", "090616");

var todaysDate = prompt(''); var regDate = document.getElementById("date");

if(todaysDate === regDate){ alert("a registration is due!");
} else { alert("No registrations are due!"); }

2 Answers

Rich Zimmerman
Rich Zimmerman
24,063 Points

first you need to set the value property of the HTML element and then grab the value in your variable like so..

var regDate = document.getElementById("date").value;

And then your conditional statement should work.

Tracy Excell
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Tracy Excell
Front End Web Development Techdegree Graduate 15,333 Points

Thank you for your help. When I put in the === date, it is still not working correctly. I will have to keep thinking about this. Please let me know if you have any other ideas on what I am doing wrong.

Also, it looks like you forgot a quote. It should be this:

var todaysDate = prompt("");
Tracy Excell
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Tracy Excell
Front End Web Development Techdegree Graduate 15,333 Points

Thank you for your help. When I put in the === date, it is still not working correctly. I will have to keep thinking about this. Please let me know if you have any other ideas on what I am doing wrong.