Skip to content

Instantly share code, notes, and snippets.

@SafaElmali
Last active December 22, 2020 05:35
Show Gist options
  • Save SafaElmali/39ebd9c1541b710f1dfc44afc9ccfbc9 to your computer and use it in GitHub Desktop.
Save SafaElmali/39ebd9c1541b710f1dfc44afc9ccfbc9 to your computer and use it in GitHub Desktop.
Hackerrank - 10 Days of Javascript - Day 3: Try, Catch, and Finally
function reverseString(s) {
try {
let SplitString = s.split("");
let ReversedArray = [];
for (let i = SplitString.length - 1, j = 0; i > -1; i-- , j++) {
ReversedArray[j] = SplitString[i];
}
console.log(ReversedArray.join("")); //4321
} catch (ex) {
console.log(ex.message)
}
}
reverseString("1234");
@jobayerahad
Copy link

This hard coded error message on line 10 can be replace by console.log(ex.message)

@SafaElmali
Copy link
Author

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment