Contact saving result is not showing in Javascript -
i wrote phone number saver in javascript. working, when search name or number in search box no result being shown:
function contact() { var nam1=prompt("please enter name"); var num1=prompt("please enter phone number"); } contact(); function search() { var searc= prompt("please enter name of contact or phone number"); } search(); //search box if ( searc == nam1 ) { alert("the phone number , " + num1); } if ( searc == num1 ) { alert("the contact name , " + nam1); }
the problem here variables scope.
try this:
var nam1; var num1; var searc; function contact() { nam1 = prompt("please enter name"); num1 = prompt("please enter phone number"); } contact(); function search() { searc = prompt("please enter name of contact or phone number"); } search(); //search box if ( searc == nam1 ) { alert("the phone number , " + num1); } if ( searc == num1 ) { alert("the contact name , " + nam1); }
Comments
Post a Comment