Apps脚本中打印到控制台

Apps脚本中打印到控制台

本文介绍了在Google Apps脚本中打印到控制台?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对编程非常陌生(已经参加了Codecademy的一些JS课程)。我试图创建一个简单的脚本来确定,如果从扑克游戏结果给出电子表格,谁应该支付给谁。我打开了Google Apps脚本,编写了以下内容:

  function addplayerstoArray(numplayers){

var playerArray = []; (i = 0; i< numplayers; i ++){
playerArray.push(i);


}
}

addplayerstoArray(7);

console.log(playerArray [3])

这个想法是创建一个包含其中玩家总数的阵列。运行代码时,我认为它会打印3到控制台。但没有发生。它说

A)我不了解Google Apps脚本控制台如何在打印方面发挥作用,以便我可以查看我的代码是完成我想要的?



B)这是代码问题吗?

解决方案

控制台不可用,因为代码在云中运行,而不是在浏览器中运行。相反,请使用GAS提供的课程:

  Logger.log(playerArray [3])

然后在IDE下的View> Logs ...下查看结果...



以下是一些关于。



编辑:2017-07-20
Apps脚本现在还提供。在查看 - 控制台日志下的脚本编辑器中查看这些日志。


I am very new to programming (have taken some of the JS courses on Codecademy). I am trying to create a simple script to determine, if given a spreadsheet with results from a poker game, who should pay whom. I opened up Google Apps Script, and wrote the following to get started:

function addplayerstoArray(numplayers) {

  var playerArray = [];

  for (i=0; i<numplayers; i++) {
    playerArray.push(i);
  }
}

addplayerstoArray(7);

console.log(playerArray[3])

The idea is to create an array with the total number of players in it. When running the code, I thought it would print "3" to the console. But nothing happened. It said

A) What do I not understand about how the Google Apps Script console works with respect to printing so that I can see if my code is accomplishing what I'd like?

B) Is it a problem with the code?

解决方案

The console is not available because the code is running in the cloud, not in your browser. Instead, use the Logger class provided by GAS:

Logger.log(playerArray[3])

and then view the results in the IDE under View > Logs...

Here's some documentation on logging with GAS.

Edit: 2017-07-20Apps script now also provides Stackdriver Logging. View these logs in the script editor under View - Console Logs.

这篇关于在Google Apps脚本中打印到控制台?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 09:32