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.makeCopy(). Then, create another variable called
secondCopyId that stores the id of
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();
let secondCopy = file.makeCopy();
let secondCopyId = secondCopy.getId();
Apps Script concepts:
@grasshopperexplainerWill you help me please??? here is my code
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.
EDIT: Why did you download my profile picture and then apply it to your profile picture??
Hello again RyanZhou. Maybe after you think my answer is strange, try reading @grasshopperexplainer’s post, the solution code is at @grasshopperexplainer’s top topic.
click or tap to revele Hey there do you like my profile picture you can wear it!! and it looks like we are friends!
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
ohhhhh sorry i just needed to tap or click
In the 8th line of your code the variable’s name is secondCopyid but the name had to give is
secondCopyId make sure the i is in capital.
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.