forked from publikwerker/basicJS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ch5_example2.html
40 lines (36 loc) · 969 Bytes
/
ch5_example2.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<!DOCTYPE html>
<html lang="en">
<head>
<title>Chapter 5, Example 2</title>
</head>
<body>
<script>
function checkCharType(charToCheck) {
var returnValue = "0";
var charCode = charToCheck.charCodeAt (0);
if (charCode >= "A".charCodeAt(0) && charCode <= "Z".charCodeAt(0)) {
returnValue = "U";
} else if (charCode >= "a".charCodeAt(0) && charCode <= "z".charCodeAt(0)) {
returnValue = "L";
} else if (charCode >= "0".charCodeAt(0) && charCode <= "9".charCodeAt(0)) {
returnValue = "N";
}
return returnValue;
}
var myString = prompt("Enter some text", "Hello World!");
switch (checkCharType(myString)) {
case "U":
document.write("First character was upper case.");
break;
case "L":
document.write("First character was lower case.");
break;
case "N":
document.write("First character was a number.");
break;
default:
document.write("First character was not a letter or a number.");
}
</script>
</body>
</html>