Google 应用程序脚本快速入门教程无法正常工作

Google apps script quickstart tutorial not working as it should

我刚开始学习编程,我选择从 Google Apps Script 开始。 我已经按照教程进行操作,但出于某种原因,它要求我创建的函数根本没有 return 预期值。我尝试了很多不同的事情,比如更改代码上的一些信息,尝试将相同的功能应用于 sheet 中的其他单元格,但是 sheet 保持 returning 错误,我无法理解,因为代码的执行没有 return 错误,并且当我开始在单元格中写她时,有关创建的新函数的预期信息出现了。

代码如下:

    /**
 * Calculates the sale price of a value at a given discount.
 * The sale price is formatted as US dollars.
 *
 * @param {number} input The value to discount.
 * @param {number} discount The discount to apply, such as .5 or 50%.
 * @return The sale price formatted as USD.
 * @customfunction
 */
function salePrice(input, discount) {
  let price = input - (input * discount);
  let dollarUS = Intl.NumberFormat("en-US", {
    style: "currency",
    currency: "USD",
});
  return dollarUS.format(price);
}

然后,它要求我在单元格“=salesPrice(100, .2)”上写下,我写下并按回车键,然后 Sheets returns me "#ERROR" 当我尝试更改此语句中的值,如“=salesPrice(100, *2)”,它会短暂显示“正在加载...”,但随后会显示 return“$NaN”。 我尝试做很多其他事情,但结果我不断收到错误消息,并且由于它只是一个初学者教程,所以预计它会起作用。 提前致谢!

根据您的语言环境(我猜),尝试

=salePrice(100;0,2)

The function separator for each Sheet is dependent on the the country chosen from File> Spreadsheet setting "Locale" - For example if you choose United States then function separator is comma but if you choose France or Brazil for instance then it will be a semicolon.