簡體   English   中英

控制台 output 沒有出現在代碼戰爭中

[英]console output does not appear in code wars

我正在做一些關於代碼戰爭的 javascript 練習。 我想通過打印到控制台來查看我的程序出了什么問題,但是除了測試結果出現在 output window 中什么也沒有。有誰知道如何在代碼戰爭中打印到控制台? 我在他們的文檔中找不到任何內容。

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";
  }
}

看到此問題: http : //www.codewars.com/users/Elistan/comments https://codewars.com/users/isbadawi/replies

從編碼的角度來看,首先存儲小寫值,然后進行比較:您需要執行以下操作:

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);

這不完全是問題的答案,而是更多的擴展答案,以便記錄可以允許在控制台中調試代碼戰的 chrome 擴展。

安裝這個 chrome 擴展: https : //github.com/bojan88/Codewars-JavaScript-debugger

這允許您使用debugger; 語句強制您的代碼在瀏覽器中運行,而不是在 codewars 服務器上的沙盒環境中運行。 效果很好。

警告:我不知道這是否安全。 使用風險自負。

關於這個問題的鏈接: 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");

這對我有用:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM