gpt4 book ai didi

javascript - 谁能告诉我我的代码有什么问题?

转载 作者:行者123 更新时间:2023-12-03 08:03:16 25 4
gpt4 key购买 nike

有人能告诉我我的代码有什么问题吗?我一直看到的错误是 Missing ;声明之前。 (第 3 行,文件“代码”)。我正在关注 YouTube 上的教程,但我不知道我的代码和导师之间有什么区别。

function createPDf () {    
let studentname = "Example Smith";
let class = "S2H";
let year = "Year 4";
let Literacy = "Working at Stage outcomes";
let Numeracy: = "Working at Stage outcomes";
let socialinteractionsclassroom = "Usually";
let socialinteractionsplayground = "Usually";
let absences = "10";
let contactteacher = "yes";
let teacehername = "Mr Jacob Example";
let effort = "Usually";

// doc id 1c-DF4cCNu8Ma5khhL6FiMudmlc7E9XGrigpWPd-06lE
// temp folder 14I2Jql8BRaK3tPh0XNa8C9IoNkYuPRir

const docFile = DriveApp.getFileById("1c-DF4cCNu8Ma5khhL6FiMudmlc7E9XGrigpWPd-06lE");
const tempFolder = DriveApp.getFolderById("14I2Jql8BRaK3tPh0XNa8C9IoNkYuPRir");
const tempFile = docFile.makeCopy(tempFolder);
const tempDocFile = DocumentApp.openById(tempFile.getId());
const body = tempDocFile.getBody();
body.replaceText("{Student name:}", studentname);
body.replaceText("{Class:}", class);
body.replaceText("{Year}", year);
body.replaceText("{Teacher Name}", teacehername);
body.replaceText("{Literacy}", Literacy);
body.replaceText("{Numeracy}", Numeracy);
body.replaceText("{Social interactions in the classroom}", socialinteractionsclassroom);
body.replaceText("{Social interactions in the playground}", socialinteractionsplayground);
body.replaceText("{Effort}", effort);
body.replaceText("{Absences exlcuding COVID}", absences);
tempDocFile.saveAndClose();

}

最佳答案

问题

尝试命名变量 class导致“Missing ; before statement”错误。

解释

ECMAScript 262 spec ,有一个关键字和保留字的列表。你 不能在为它们定义的任何其他上下文中使用它们(有些甚至为将来保留)。

保留字列表ATTOW

等待 |休息 |案例 |捕获|类(class) |常量 |继续 |调试器 |默认 |删除 |做 |否则 |导出 |延伸 |假 |最后 |为|功能 |如果 |进口 |在|实例 |新 |空 |返回 | super |开关 |这个 |扔|真实 |试试|类型 |变量 |无效 |而|与 |屈服

留作 future

枚举 |工具 |接口(interface) |包装 |私有(private) | protected |上市

关于错误消息

您会看到不太有用的错误消息,因为您的脚本在旧的 Rhino runtime 下运行。使用气体。如果您使用的是新版本 V8(请尽快执行 migrate),您会收到以下信息:

SyntaxError: Unexpected token 'class'



实际上,还有第二个问题会导致错误 - 使用冒号和 assignment operator不是有效的 JS 语法,但所有功劳都应该归功于另一个答案:

SyntaxError: Unexpected token ':'

关于javascript - 谁能告诉我我的代码有什么问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62400578/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com