Input Numbers Described

[Total: 0    Average: 0/5]

This determines if an input value is odd, even, positive or negative.

Body Code:

<script>
var CONT=true; /* set to true so it will enter loop */
var MSG="Enter a number (zero exists loop)";
var DEF="0";
var _MSG="<BR>Your number is <B>";

while(CONT) 
{ 
  var INPUT = window.prompt(MSG,DEF);
  /* this checks to see if the number is a signed integer or not */
  var IS_NUM = parseInt(INPUT)==INPUT;
  var EVEN_ODD;
  var POS_NEG;
  if(IS_NUM && INPUT)
  {
    EVEN_ODD=INPUT%2?"odd":"even";
	POS_NEG=INPUT>0?"positive":"negative";
	document.write(_MSG+INPUT+"</B> and this is "+EVEN_ODD+".");
	document.write(_MSG+INPUT+"</B> and this is "+POS_NEG+".");
  }
  /* stop if a not a signed integer or if zero is input */
  if(!IS_NUM || INPUT==0)
  {
    if(IS_NUM)
      document.write(_MSG+INPUT+"</B> and this is zero.");
	else
	  document.write("<BR>Your input is <b>"+INPUT+"</B> and it is not a signed integer.");
    CONT=false;
  }
  if(CONT)
    document.write("<HR>");
}
</SCRIPT> 

Times Viewed: 5

Leave a Reply

Your email address will not be published. Required fields are marked *