Last active
December 22, 2020 05:35
-
-
Save SafaElmali/39ebd9c1541b710f1dfc44afc9ccfbc9 to your computer and use it in GitHub Desktop.
Hackerrank - 10 Days of Javascript - Day 3: Try, Catch, and Finally
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This hard coded error message on line 10 can be replace by
console.log(ex.message)