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

Popular posts from this blog

Php operator `break` doesn't stop while -

ubuntu - Bash Script to Check That Files Are Being Created -

vim: Search & replace -