You are viewing a single comment's thread. Return to all comments →
Hi Can someone explain why this makes the test to fail (while the output is ok..) ? Thanks in advance
'use strict'; process.stdin.resume(); process.stdin.setEncoding('utf-8'); let inputString = ''; let currentLine = 0; process.stdin.on('data', function(inputStdin) { inputString += inputStdin; }); process.stdin.on('end', function() { inputString = inputString.split('\n'); main(); }); function readLine() { return inputString[currentLine++]; } function main() { const S = readLine(); try { const parsed = parseInt(S, 10) if (!/^\d+$/.test(S) || isNaN(parsed)) { throw new Error("Bad String"); } console.log(parsed); } catch (err) { console.log("Bad String"); } }
Seems like cookies are disabled on this browser, please enable them to open this website
Day 16: Exceptions - String to Integer
You are viewing a single comment's thread. Return to all comments →
Hi Can someone explain why this makes the test to fail (while the output is ok..) ? Thanks in advance