Write A Script That Inputs Five Numbers And Outputs Number Of Positive/Negative numbers And Number of Zeros Using Javascript

LEVEL: Beginner

Whats in this post?

  1. Code
  2. Output
  3. Background and Explanation of the code


To copy code: Click  View Source “View Source” on the right of this code snippet.

Background and Explanation of the code

  1. This code snippet takes five numbers from the user using JavaScript’s ‘prompt’ method, stores in an array ‘input’ and outputs the number of positive numbers, negative numbers and number of zeros.
  2. After storing values in input, simple comparison has been done using if-else-if statement to determine whether the number is positive, negative or zero. After comparison, result is printed using JavaScripts’ document.write() method.


total positive number = 3
total negative number = 1
total zero inputs = 1