Sort by

recency

|

256 Discussions

|

  • + 1 comment

    Looks like there is something wrong with the compiler. I keep getting 6 lines of output when there are only 4 inputs from the test cases. Are you seeing the same thing?

    • + 0 comments

      Oh, I found the reason. I was supposed to write a return statement inside the isPositive() function instead of console.log. The stub code has a console.log and it will print the result of the return statement.

  • + 0 comments

    Here's my solution:

    function isPositive(a) {
        try {
            if (a === 0) throw new Error('Zero Error');
            if (a < 0) throw new Error('Negative Error');
            return 'YES';
            }
        catch (error) {
            return error.message;
        }
    }
    
  • + 0 comments
    function isPositive(a) {
      if (a > 0) {
        return "YES";
      } else if (a === 0) {
        throw new Error("Zero Error");
      } else {
        throw new Error("Negative Error");
      }
    }
    
  • + 0 comments
    function isPositive(a) {
        
            try{
                if(a>0){return "YES"}
                if(a==0){throw new Error("Zero Error")}
                if(a<0){throw new Error("Negative Error")}
            }catch (e){
                return e.message
            }
        
    }
    
  • + 0 comments

    function isPositive(a) { const verify = a;

    if (verify >= 1) { 
        return 'YES'
    } else if (verify === 0) {
        throw new Error('Zero Error')
    } else {
        throw new Error('Negative Error')
    }
    

    }