检查第一个单词是否是大写的,解决方案是否为false

时间:2017-09-24 21:38:37

标签: javascript

在[0]之前的

肯定是大写的,所以我很困惑为什么它会评估为假

function myReplace(str, before, after) {
    console.log(before[0] === before[0].toUpperCase();
}

myReplace("A quick brown fox jumped over the lazy dog", "Jumped", "leaped");

3 个答案:

答案 0 :(得分:1)

你指的是toUpperCase函数。你需要调用它才能获得值



function myReplace(str, before, after) {
    console.log(before[0] === before[0].toUpperCase());
}

myReplace("A quick brown fox jumped over the lazy dog", "Jumped", "leaped");




答案 1 :(得分:0)

这次你忘了关闭console.log,它应该是:

  function myReplace(str, before, after) {
    console.log(before[0] === before[0].toUpperCase());
}

myReplace("A quick brown fox jumped over the lazy dog", "Jumped", "leaped");

答案 2 :(得分:0)

天啊,你应该添加括号:

function myReplace(str, before, after) {
    console.log(before[0] === before[0].toUpperCase());
}

myReplace("A quick brown fox jumped over the lazy dog", "Jumped", "leaped");