Javascript 谁能告诉我我的代码有什么问题吗?
有人能告诉我我的代码有什么问题吗?我一直看到的错误是,丢失了;在声明之前。(第3行,文件“代码”)。我正在关注YouTube上的一个教程,我不知道我的代码和教程有什么区别Javascript 谁能告诉我我的代码有什么问题吗?,javascript,google-apps-script,syntax-error,reserved-words,Javascript,Google Apps Script,Syntax Error,Reserved Words,有人能告诉我我的代码有什么问题吗?我一直看到的错误是,丢失了;在声明之前。(第3行,文件“代码”)。我正在关注YouTube上的一个教程,我不知道我的代码和教程有什么区别 function createPDf () { let studentname = "Example Smith"; let class = "S2H"; let year = "Year 4"; let Literacy = "Working at Stage outcomes"
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();
}
以下是我认为可能的原因:
let class = "S2H"; // class is a reserved words, so it cannot be used as a variable
let Numeracy: = "Working at Stage outcomes"; // the colon goes after Numeracy is wrong naming variable rule. You should remove or change it
我的英语不好,希望你能理解我的意思 以下是我认为可能的原因:
let class = "S2H"; // class is a reserved words, so it cannot be used as a variable
let Numeracy: = "Working at Stage outcomes"; // the colon goes after Numeracy is wrong naming variable rule. You should remove or change it
我的英语不好,希望你能理解我的意思 问题 尝试命名变量
class
会导致“Missing;before语句”错误
解释
在中,有一个关键字和保留字的列表。您不能在为它们定义的任何其他上下文中使用它们(有些甚至是为将来保留的)
保留字列表
等待| break | case | catch | class | const | continue | debugger | default | delete | else | export | extends | false | finally | for | function | if | import | in | instanceof | var | new null | return
为未来保留
枚举|实现|接口|包|私有|受保护|公共
出现错误消息时
您会看到一条没有太大帮助的错误消息,因为您的脚本在使用的旧GAS下运行。如果您使用了新的V8(请尽快),您将收到以下信息:
SyntaxError:意外标记“类”
事实上,还有第二个问题会导致错误-使用冒号with不是有效的JS语法,但请注意,所有问题都应归于另一个答案: 语法错误:意外标记“:”
问题 尝试命名变量
class
会导致“Missing;before语句”错误
解释
在中,有一个关键字和保留字的列表。您不能在为它们定义的任何其他上下文中使用它们(有些甚至是为将来保留的)
保留字列表
等待| break | case | catch | class | const | continue | debugger | default | delete | else | export | extends | false | finally | for | function | if | import | in | instanceof | var | new null | return
为未来保留
枚举|实现|接口|包|私有|受保护|公共
出现错误消息时
您会看到一条没有太大帮助的错误消息,因为您的脚本在使用的旧GAS下运行。如果您使用了新的V8(请尽快),您将收到以下信息:
SyntaxError:意外标记“类”
事实上,还有第二个问题会导致错误-使用冒号with不是有效的JS语法,但请注意,所有问题都应归于另一个答案: 语法错误:意外标记“:”
哪一行是第3行?让studentname=“Example Smith”;你确定这是Code.gs页面吗?我不认为你可以使用单词class作为变量名,因为它是ES6@Jacob-请阅读上的ECMAScript规范,Cooper完全正确,这就是导致错误的原因。第3行是什么?让studentname=“Example Smith”;你确定这是Code.gs页面吗?我不认为你可以使用单词class作为变量名,因为它是ES6@Jacob-请阅读ECMAScript规范,Cooper是绝对正确的,这就是导致错误的原因。请考虑将解释从代码中分离出来,使其更加可见-它是正确的,但我,比如说,差点错过了it@OlegValter我将在下一个问题中回答。非常感谢你提醒我:“PucDunh -请考虑把解释从代码中分离出来,使它更清晰——它是正确的,但是我,例如,几乎错过了。”it@OlegValter我将在下一个问题中回答。非常感谢你提醒我:)