javascript - How to find the number of positive and negative numbers are there on an input field? -


my question there 3 input text field , button, whatever user enters , press button, alert should how many negative numbers , how many positive numbers on text field?

here working example code explained below.

if want enter number in each of text field , click button tells number of positive , negative numbered entered here code,

you html code,

<input id="one" type="text"/> <input id="two" type="text"/> <input id="three" type="text"/> <input type="button" onclick="check();" value="check"> 

now can write script follows,

function check(){      //converting values integer     var x = parseint(document.getelementbyid("one").value);     var y = parseint(document.getelementbyid("two").value);     var z = parseint(document.getelementbyid("three").value);      //initializing positive , negative count 0      var poscount = 0;     var negcount = 0;      //incrementing postive , negative count depending whether      positive or negative     if(x>=0){         poscount++;     }else{         negcount++;     }     if(y>=0){         poscount++;     }else{         negcount++;     }     if(z>=0){         poscount++;     }else{         negcount++;     }     alert("positive numbers: "+poscount);     alert("negative numbers: "+negcount); } 

Comments

Popular posts from this blog

javascript - oscilloscope of speaker input stops rendering after a few seconds -

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -