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 me solve the variable problem in the code chanllege sector

I got a problem in one sector of code chanllege, here is the details:

Question: Open a new script tag and using the "validEmail" plugin, store in a variable "isValid" whether the email address in the text input is valid.

My answer:

        <script type="text/javascript" src="validEmail.js">
            $("input")validEmail({
              var isValid:ture
            })
          </script>

But it's wrong, and I got a warning like this: The validEmail method wasn't called on input

Thank you in advance

8 Answers

I'm getting the error "The validEmail method wasn't call on input" and I've been looking through all the forums and trying several things with no success... suggestions?

<script>
var isValid = $("input").validEmail();
var isValid = true;
});
</script>

This finally worked... changed the = to : <script> var isValid = $("input").validEmail(); var isValid :true; </script>

It looks like I cannot paste the HTML code directly here, can anyone tell me what is the right way to paste my code?

Guil Hernandez
STAFF
Guil Hernandez
Treehouse Teacher

@Hao,

Check out the Markdown Cheatsheet link below, which explains everything. Here's the part on posting code:

Indent your sentence with 4 spaces (or a single tab) to turn it into a code block.
Ben Jakuben
STAFF
Ben Jakuben
Treehouse Teacher

Where you typed "My answer" has a type for "true"...you have it "ture". If that's your actual code that might be the problem.

@Guil, WOW, it works! BTW, I am wondering that is there any way to indent all lines together at once? I am indenting every line one by one right now which is really a waste of time

Andrew Chalkley
STAFF
Andrew Chalkley
Treehouse Guest Teacher

Hi Hao,

If you're still having issues here's the general principles of the question.

First include this:

<script type="text/javascript" src="validEmail.js"></script>

Then open an new script tag afterwards, I saw you put your JavaScript in the same script tag. This won't get executed. So you should have this:

<script type="text/javascript" src="validEmail.js"></script>
<script>
    //Put your code in here.
</script>

To set a variable its var variableName an equal sign and then the value. To call a method on a selected element it's a dot notation so something like this $("css selector").methodName();.

Regards

Andrew

@Chalkley, I've made it. Thank you for your instruction :)

Best, Hao

@Trish good one. One thing to note though if u would read that comment.

To anyone still struggling with this...... heres the answer below

<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="validEmail.js"></script>
<script>

  var isValid = $("input").validEmail();
  isValid:true;    // variable declared only once as it is globally accessible.


</script>