Day 16: Exceptions - String to Integer

  • + 2 comments

    Not sure if the challenge/test-cases make sense as they are for a language like JS. Here my submission after a number of failed attempts (plus the obvious frustration), in case it helps. The challenge is easy. You are supposed to put the time practicing, not making HR work.

    function main() {
        const S = readLine();
        const N = Number(S);
        const throwsError = () => { throw new Error("Bad String") };
    
        try {
            isNaN(N) ? throwsError() : console.log(N);
        } catch(error) {
            console.log(error.message);
        }
    }