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

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -