老师帮忙看下问题
来源:3-31 编程练习
晚风142536
2020-02-15 17:20:26
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script>
function Upperstr(str){
var str1=str.split(" ");
//console.log(str1);
for(var i=0,len=str1.length;i<len;i++){
var word=str1[i];
//console.log(word);
var word1=str1[i].toUpperCase();
//console.log(word1);
var newstr=word1.join("-");
//console.log(newstr);
}
return newstr;
}
var newstr=Upperstr("all time is no time when it is past");
document.write(Upperstr(str));
</script>
</body>
</html>
1回答
好帮手慕粉
2020-02-15
同学你好,当老师运行同学的代码时,控制台报如下错误:

这是因为join是数组的方法,而word1是字符串,所以报错。修改参考:

如果我的回答帮助了你,欢迎采纳,祝学习愉快~
相似问题