JSFiddle - React, Tailwind, and code Playground

by Paulpro

JavaScript

function factorial(x){
    if(x < 0){
        setTimeout(function(){
            throw "X can't be less than 0 you fool!"; 
        }, 1);
        return false;
    }
    return x == 0 ? 1 : x*factorial(x-1);
}

try{
    factorial(-1);
}catch(e){
    console.log('Test');
}