Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 2ea6fdc

Browse files
Create throwException.js
1 parent c72aad4 commit 2ea6fdc

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

‎Javascript/throwException.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*Given a character X you need to find whether X is an alphabet or not.
2+
3+
If yes, return a string "Yes" or otherwise throw an error with the message "Not Alphabet".
4+
*/
5+
6+
function isAlphabet(X) {
7+
8+
let value = checkAlphabet(X)
9+
if(value){
10+
return "Yes"
11+
}else{
12+
throw "Not Alphabet"
13+
}
14+
};
15+
16+
function checkAlphabet(X) {
17+
let n = X.charCodeAt(0);
18+
let strStartsWithALetter = (n>=65 && n < 91) || ( n>=97 && n<123);
19+
if (strStartsWithALetter) {
20+
// Yes, it starts with an alphabet
21+
return true;
22+
} else {
23+
// No, it doesnt start with an alphabet
24+
return false;
25+
}
26+
}
27+
module.exports = isAlphabet;
28+
console.log(isAlphabet('a'))

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /