javascript - If statement not executing when credentials are met -
javascript - If statement not executing when credentials are met -
i'm trying create simple code checks if phone number entered user in proper format, if statement not execute when 3 credentials met, print "please type phone number..." or blank screen, if type in number correctly.
var phonenumber=prompt("what 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 "+phonenumber+", give thanks you.");} else {document.write("please type phone number in proper format (555-555-1234)");}
seconddash
spelled wrong in condition, you're missing sec d
- have console open when developing.. have seen:
uncaught referenceerror: secondash not defined
javascript if-statement
Comments
Post a Comment