Created
October 20, 2021 14:10
-
-
Save rgwozdz/076c0bb23c3e2fd70d974d6385dc5bd9 to your computer and use it in GitHub Desktop.
Refactoring challenge
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 getErrorMessage(code) { | |
if ( | |
code === 702 || | |
code === 1082 || | |
code === 1083 || | |
code === 1114 || | |
code === 1184 || | |
code === 1266 || | |
code === 12403 | |
) { | |
return "Bad Input"; | |
} else if ( | |
code === 20 || | |
code === 21 || | |
code === 23 || | |
code === 24 || | |
code === 26 || | |
code === 700 || | |
code === 701 || | |
code === 790 || | |
code === 1700 || | |
code === 2202 || | |
code === 2203 || | |
code === 2204 || | |
code === 2205 || | |
code === 2206 || | |
code === 3734 || | |
code === 3769 || | |
code === 12396 | |
) { | |
return "Forbidden"; | |
} else { | |
return "Internal Server Error"; | |
} | |
}; | |
console.assert(getErrorMessage(702) === 'Bad Input', 'should have been "Bad Input"') | |
console.assert(getErrorMessage(20) === 'Forbidden', 'should have been "Forbidden"') | |
console.assert(getErrorMessage(99999) === 'Internal Server Error', 'should have been "Internal Server Error"') | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment