这是一个检查首字母大小写的代码,谁能帮我看看哪里错了啊?多谢!

<html>
<head>
<script language="JavaScript" type="text/javascript">
function checkCharType(charToCheck)
{
    var returnvalue = "O";
    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;
}
</script>
</head>


<body>
<script language="JavaScript" type="text/javascript">

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 character or a number")
}
</script>


</body>
</html>

海贼12345
浏览 1377回答 1
1回答

杰杰就是我

请检查你的 checkCharType 方法中的  赋值语句写的问题 returnvalue = "N;"这样 你返回的是  '字母'+';'的形式 ,如  'L;'  所以肯定不能判断  应该写成  returnvalue = "N";其他, 同理改正即可
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript