Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript jQuery Basics (2014) Creating a Password Confirmation Form Perform: Part 2

Lotte Bloem
Lotte Bloem
18,630 Points

What am i doing wrong .. have checked my code now 10 times. And its still not working

//Problem: Hints are shown even when form is valid
//Solution: Hide and show team at appropriate times
var $password = $("#password");
var $confirmPassword = $("confirm_password");
//hide hints
$("form span").hide();

function passwordEvent(){
  //Find out if password is valid
  if($password.val().length > 8) {
    //Hide hint if valid
    $password.next().hide();
  } else {
    //Else show hint
     $password.next().show();
  }
}
function confirmPasswordEvent() {
  //Find out if password and confirmation match
   if($password.val() === $confirmPassword.val()) {
    //Hide hint if match
     $confirmPassword.next().hide();
   } else {
    //Else show hint
     $confirmPassword.next().show();
   }
}

//When event happens on password input
$password.focus(passwordEvent).keyup(passwordEvent).focus(confirmPasswordEvent).keyup(confirmPasswordEvent);



//When event happens on confirmation input
$confirmPassword.focus(confirmPasswordEvent).keyup(confirmPasswordEvent);
Konrad Pilch
Konrad Pilch
2,435 Points

I think you need to write javascript and add three of the dashes, like you did before, but then add a line break , see if i can show it :

<h1>You need to insert

 ```javascript

JS code

```close it but dont write any words here
Konrad Pilch
Konrad Pilch
2,435 Points

Sorry but im at college and i cant open it and i dont see anything wrong + im a newbie to it as well so i wont spot hings by hand. Id be able to look at the code properly in 3 hours.

But tbh, what i do when i learn from a treehouse course or video, is i downolad the course 'File Project' and then look for the file and e.g copy code of blocks and see if it works, first of all copy the whole to see if the code is still valid.. and then look for errors block by block or line by line and see if it works .

6 Answers

It seems that you have just forgot to initialize the $confirmPassword variable to the confirm_password id. Just add the id selector like you did when initializing the $password variable and that should fix the error.

So declare and initialize like this: var $confirmPassword = $("#confirm_password");

Konrad Pilch
Konrad Pilch
2,435 Points

Hii again :D Could could you look at Markdown Cheatsheet , its just above the ' Post answer' button. O its right you have notify and above all that you have 'Refference this markdown Cheatseet ...@' could you look how to format the code please? its hard to read without the highighter . Put javascript or js after the ` u'd understand dit if you read it : p

Lotte Bloem
Lotte Bloem
18,630 Points

Finally! Thanks hope you can see now what i did wrong.

Lotte Bloem
Lotte Bloem
18,630 Points

It doesnt give any error's .. i checked with ctril+shift+j and i checked the code on codepen.io And i am a new with this as well. I hope someone can tell me what i did wrong before i can do more.

Konrad Pilch
Konrad Pilch
2,435 Points

Have you written this by your self? or was it in project files as well? If it was you can downolad it there and look line by lane if it works. If you know what i mean.

Or just re-write it by the time someone will give the answer. You have a copy here incase something goes wrong and you can save it as well.

Lotte Bloem
Lotte Bloem
18,630 Points

The teacher explaned and i did write it over. So he made the code i just type it over on this course.

Jenny Veens
Jenny Veens
10,896 Points

Hi Lotte,

Where is confirm_password stored? It looks like you're trying to grab the value with jQuery, but you're not using a class name, id, or element type.

This line might be why it's not working :

var $confirmPassword = $("confirm_password");

Try console.log($confirmPassword) to ensure it's logging out the correct value.

Konrad Pilch
Konrad Pilch
2,435 Points

confirm_password should be a class or an id i think? right? it remind me of PHP logic and the above applies it.

Lotte Bloem
Lotte Bloem
18,630 Points

It worked later on codepen.io i dont know why it don't work when i check it on the usual way. But thanks for helping me.