简体   繁体   English

控制台 output 没有出现在代码战争中

[英]console output does not appear in code wars

I'm doing some javascript exercises on code wars.我正在做一些关于代码战争的 javascript 练习。 I want to see what's going wrong in my programs by printing to the console, but nothing except the test results appears in the output window. Does anyone know how to print to the console in code wars?我想通过打印到控制台来查看我的程序出了什么问题,但是除了测试结果出现在 output window 中什么也没有。有谁知道如何在代码战争中打印到控制台? I can't find anything in their documentation.我在他们的文档中找不到任何内容。

function areYouPlayingBanjo(name) {
  // Implement me
  var person = name.split('');
  person[0].toLowerCase();
  console.log(person[0]);
  if(person[0] === 'r'){
    return name + " plays banjo";
  }
  else{
    return name + " does not play banjo";
  }
}

see this issue: http://www.codewars.com/users/Elistan/comments https://codewars.com/users/isbadawi/replies 看到此问题: http : //www.codewars.com/users/Elistan/comments https://codewars.com/users/isbadawi/replies

from coding point of view first store the lower case value then compare:you need to do something like this: 从编码的角度来看,首先存储小写值,然后进行比较:您需要执行以下操作:

function areYouPlayingBanjo(name) {
      // Implement me
      var person = name.split('');
      console.log(person);
     var x= person[0].toLowerCase();
      console.log(person[0],x);// see difference here
      if(x === 'r'){// if you will use person[0] it will not match from given input because it will be R
        return name + " plays banjo";
      }
      else{
        return name + " does not play banjo";
      }
    }

var out = areYouPlayingBanjo('Rikke, rikke and Martin');
    console.log(out);

This is not exactly an answer to the question, but more of an extended answer in order to document a chrome extension that can allow debugging in the console for codewars.这不完全是问题的答案,而是更多的扩展答案,以便记录可以允许在控制台中调试代码战的 chrome 扩展。

Install this chrome extension: https://github.com/bojan88/Codewars-JavaScript-debugger安装这个 chrome 扩展: https : //github.com/bojan88/Codewars-JavaScript-debugger

This allows you to use the debugger;这允许您使用debugger; statement to force the your code to run in the browser rather than the sandboxed environment on the codewars servers.语句强制您的代码在浏览器中运行,而不是在 codewars 服务器上的沙盒环境中运行。 Works great.效果很好。

Caveat: I don't know if this is safe.警告:我不知道这是否安全。 Use at your own risk.使用风险自负。

Link about this question : https://www.codewars.com/kata/are-you-playing-banjo/train/javascript关于这个问题的链接: https : //www.codewars.com/kata/are-you-playing-banjo/train/javascript

 const areYouPlayingBanjo = n => (n[0] == 'R' || n[0] == 'r') ? `${n} plays banjo` : `${n} does not play banjo` console.log(areYouPlayingBanjo("Martin"), "Martin does not play banjo"); console.log(areYouPlayingBanjo("Rikke"), "Rikke plays banjo");

This worked for me:这对我有用:

Console.Out.WriteLine("Print stuff to output here.");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM