In this HackerRank Day 3: Throw 10 days of javascript problem solution Complete the isPositive function below. It has one integer parameter, a. If the value of a is positive, it must return the string YES. Otherwise, it must throw an Error according to the following rules:
  1. If a is 0, throw an Error with message = Zero Error.
  2. If a is negative, throw an Error with message = Negative Error.


HackerRank Day 3: Throw problem solution


Problem solution in JavaScript programming.

/*
 * Complete the isPositive function.
 * If 'a' is positive, return "YES".
 * If 'a' is 0, throw an Error with the message "Zero Error"
 * If 'a' is negative, throw an Error with the message "Negative Error"
 */

function isPositive(a) {
   
    if (a > 0) {
        return 'YES'
    }
    else
    {    
         var e = new Error();
         e.message='someother Error'     
         if (a == 0 )
            {
            e.message='Zero Error';
            }else {
            e.message='Negative Error';
            }
        throw e;

     }
     }