If the statement does not execute when the credentials are met

advertisements

I'm trying to make a simple code that checks if the phone number entered by the user is in the proper format, but my if statement will not execute when all three credentials are met, it will only print the "please type the phone number..." or a blank screen, even if I type in the number correctly.

    var phonenumber=prompt("What is your phone number?", "");
var firstdash=phonenumber.charAt(3);
var seconddash=phonenumber.charAt(7);
var length=phonenumber.length;
if(firstdash=='-' && secondash=='-' && length==12)
    {document.write("Your phone number is "+phonenumber+", thank you.");}
else
    {document.write("Please type the phone number in the proper format (555-555-1234)");}


seconddash is spelled wrong in your condition, you're missing the second d - always have your console open when developing.. you would have seen:

Uncaught ReferenceError: secondash is not defined