请老师帮忙查下错哈
来源:3-16 编程练习
a早安
2021-01-04 21:35:32
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title>toUpperCase和toLowerCase</title>
</head>
<body>
<script>
var str = "Never deter till tomorrow that which you can do today";
var index = str.indexOf('tomorrow');//补充代码
var strNew = str.charAt(index, (index + 8));//补充代码
var upperStr = strNew.toUpperCase();//补充代码
document.write(upperStr);
</script>
</body>
</html>
1回答
同学你好,截取字符串“tomorrow”使用charAt()方法不对,charAt()是用来查找某个子字符串的位置的,不是用来截取某个子字符串的。可以使用substr()方法截取字符串tomorrow”,参考如下修改:
另外,被截取的子字符串转换为大写的之后,需要和原来的字符串拼接,如下:
祝学习愉快~
相似问题