Home  • Programming • JavaScript

Numbers Program: Positive, Negative, and Zero numbers

Given a list of numbers, find out how many are positive, how many are negative, and how many are zero. 16,3,-7,0,4,-6,-2,8
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Numbers Program</title>
</head>

<body>
<script>
var card=[16,3,-7,0,4,-6,-2,8];

var p=0;
var n=0;
var z=0;

for(var index in card){
  number=card[index];
  
  if(number>0){
	     p=p+1;  
  }else if(number<0){
	     n=n+1;
  }else{
     z=z+1;
  }
  
}//end loop

document.write("Positive:"+p);
document.write("<br/>");
document.write("Negative:"+n);
document.write("<br/>");
document.write("Zero:"+z);

</script>

</body>
</html>

Comments 2


Thank u sir.
thank you
Copyright © 2024. Powered by Intellect Software Ltd