Shreyas arya

Generation

generate functionFri, 10 Feb 2023

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

Script function printString(str){ if(typeof str !== "string"){ throw new Error("Argument not a string"); } console.log(str) return str; } for(var i = 0; i < 3; i++){ try{ printString("hello"); }catch(e){ console.log("error: " + e); } }

Questions about programming?Chat with your personal AI assistant