Aim of the puzzle: Use Apps Script to create a copy of a file in Drive and print its id.
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. Another example is .getId(), which gets the id of a file from Drive.
To complete the puzzle, create a variable called secondCopy that stores a new copy of file using file.makeCopy(). Then, create another variable called secondCopyId that stores the id of secondCopy using secondCopy.getId(). Finally, print secondCopyId to the console.
Sample code solution:
let id = '1gJAiEKJd8NMdjI_EcI12y3iIYk3E8wokAJEOijsZcf0';
let file = DriveApp.getFileById(id);
let firstCopy = file.makeCopy();
let firstCopyId = firstCopy.getId();
console.log(firstCopyId);
let secondCopy = file.makeCopy();
let secondCopyId = secondCopy.getId();
console.log(secondCopyId);
Hi there RyanZhou. Happy to help!
At line 9, you wrote secondCopyid but inside your print() statement, you’re printing secondCopyId, even though it is not defined yet. Try renaming it to secondCopyId variable. Hope this makes you pass.
Hope this help. If this solution did not work then ask me any question.
Pummarin
EDIT: Why did you download my profile picture and then apply it to your profile picture??
click or tap to reveal Your profile picture is so cool and I like it before I changed my profile picture of moose and Pummarin_The_Gamer! here is the picture! Screen Shot 2020-09-13 at 6.07.35 pm|690x386
um… i cant see anything i’m going to get mad knowwwwwwwww show me what it says i hope you read my part that i just did okay so you can know all about me and your not going to like it i’m telling you right know your not going to like it
I’m a bit confused or I might just not understand. I thought that variables were just ways to store information, but you still needed to call that variable in some other line of code for that variable’s code to execute.
In this exercise, we are creating variables but I don’t see where we are telling it to run. We are using console.log to print out the file id of both files, but that appears to be it. Sorry if it’s a dumb question.