Shreyas arya

Generation

generate functionFri, 10 Feb 2023

Create a method print a string If type is not string then throw exception and retry the method for 3 times

Script function printString(str) { if (typeof str === 'string') { console.log(str); } else { throw new Error('input is not a string'); } } try { printString(1); } catch (e) { var retryCount = 3; while (retryCount-- > 0) { printString(1); } }

Questions about programming?Chat with your personal AI assistant