Javascript 你能帮我查一下控制台日志吗?

Javascript 你能帮我查一下控制台日志吗?,javascript,Javascript,我要数一数X和Y 但我的控制台日志不起作用,可能出了问题 如果与[i]匹配,则包括(某物)=“true” var input=“10W5N2S6E”; var matches=input.split(/(?您需要使用toLowerCase(),因为includes()区分大小写 另外,无需比较includes()==“true”,因为它返回一个布尔值,对于if条件(它将基于该布尔值条件执行下一个block语句)就足够了 var input=“10W5N2S6E”; var matches=in

我要数一数X和Y 但我的控制台日志不起作用,可能出了问题 如果与[i]匹配,则包括(某物)=“true”

var input=“10W5N2S6E”;

var matches=input.split(/(?您需要使用
toLowerCase()
,因为
includes()
区分大小写

另外,无需比较
includes()==“true”
,因为它返回一个布尔值,对于if条件(它将基于该布尔值条件执行下一个block语句)就足够了

var input=“10W5N2S6E”;

var matches=input.split(/(?Comparation`==“true”`是不需要的,它可以是
true
,而不需要
。如果(匹配[i].includes(“s”)
)是区分大小写的,您就可以
,而不是
“true”
返回
true
(布尔值),而不是
“true”
“false”“
(字符串)。另外,
如果(a==true)
相当于
如果(a)
输出1和3是
NaN
?这是因为行:x=x-matches[i];//x是数字,matches[i]是字符串我不明白代码应该做什么,所以我只对明显的错误进行了注释和重构,我清楚的是什么
    var input = "10W5N2S6E";
var matches = input.split(/(?<=[A-Z])(?=\d)/);
for (let i = 0; i < matches.length; i++) {
  let x = 0;
  let y = 0;
  if (matches[i].includes("w") == "true") {
    x = x - matches[i];
    console.log(x);
  }
  if (matches[i].includes("e") == "true") {
    x = x + matches[i];
    console.log(x);
  }
  if (matches[i].includes("n") == "true") {
    y = y + matches[i];
    console.log(y);
  }
  if (matches[i].includes("s") == "true") {
    y = y - matches[i];
    console.log(y);
  }
}