Rename the Copy Explainer

Aim of the puzzle: Use Apps Script to create and rename a copy of a file in Drive.

Walk through of the solution: Apps Script has custom code functions that connect to Drive. One example is .makeCopy(), which creates a copy of a file from Drive. It returns a new file that has the same contents as the file it copied but a different id.

If .makeCopy() is given a string as an argument, it will set the name of the copy to that string. For example, file.makeCopy('I am a copy!') will set the name of the copy to 'I am a copy!'. If .makeCopy() is used without an argument, the copy will have the default title 'Copy of [file name]'.

To complete the puzzle, create a variable named secondCopy that stores a new copy of file using file.makeCopy(). Then, add a string as an argument inside the parentheses of .makeCopy().For example, file.makeCopy('Copy 2 of Inventory of Cat Toys'). Next, create a variable called secondCopyName that stores the name of the copy using .getName(). Finally, print secondCopyName to the console.

Sample code solution:

let id = '1gHAiEKJd8NMdjI_EcI12y3iIYk3E8wokAJEOijsZcf0';
let file = DriveApp.getFileById(id);

let firstCopy = file.makeCopy('Copy 1 of Inventory of Cat Toys');
let firstCopyName = firstCopy.getName();
console.log(firstCopyName);

let secondCopy = file.makeCopy('Copy 2 of Inventory of Cat Toys');
let secondCopyName = secondCopy.getName();
console.log(secondCopyName);

JavaScript concepts: Variables, Strings

Apps Script concepts: DriveApp, .getFileById(), .makeCopy(), .getName()

Hello! I was doing this challenge and for some reason, I keep getting a “TypeError: Cannot read property ‘apply’ of undefined” message. I went here and copied the solution code-for-code but it won’t work. Here’s my code:
image
What should I do? Am I missing something?

Hi!
Try to change getname() to getName().

alright this meme might be funny,its clean,nothing wrong but there is 19919% something wrong with the image.
Oi josuke! this image is clickbait! its not real!


it is not real ngl
i hate my own meme urggggggggggggggggg
-Rezzie

let id = ‘1gHAiEKJd8NMdjI_EcI12y3iIYk3E8wokAJEOijsZcf0’;
let file = DriveApp.getFileById(id);

let firstCopy = file.makeCopy(‘Copy 1 of Inventory of Cat Toys’);
let firstCopyName = firstCopy.getName();
console.log(firstCopyName);

let secondCopy = file.makeCopy(‘Copy 2’);
let secondCopyName = secondCopy.getName();
console.log(secondCopyName)

This is the answer