In this video, you will write the code for a personalized *alert.* Creating an *alert* is the first step to making a pop-up message that greets your readers when they open your document.
You’ll work in your “Opening Message” project in the Script Editor.
As you write, be precise.
One wrong character will keep your code from working properly.
It’s okay to make mistakes, though!
You can always go back and modify your code.
First, tell the code to show your message in your document.
Between the highlighted curly braces, type “DocumentApp” with a capital D and A, and no spaces between the words.
Type a period at the end of “DocumentApp.”
An autocomplete menu appears.
If the menu doesn’t appear when you type a period, check your spelling and capitalization.
The autocomplete menu keeps you from having to type or remember every piece of code.
Scroll down the autocomplete menu, and select “getUi” This tells the computer to “get” the “user interface,” or the screen you type in, from Google Docs.
The line of code looks like this.
At the end of that line of code, type a period.
The autocomplete menu appears again.
Next, write code that will show a message.
This is called an alert.
From the autocomplete menu, choose “alert(String prompt) : Button.”
Take a look at your code so far.
It reads, “Use the Google Docs App and the display screen for the document to make an alert box appear.”
Next, customize your code by typing a unique message for the alert.
The code that gives the computer instructions has to be exact.
But the text you type *inside* the parentheses can be anything you like.
Replace the highlighted word “prompt” with your alert message.
You can write whatever you want for your welcome message, but make sure it is appropriate.
Put double quotation marks around your message.
This is called a “parameter.”
In computer science, a parameter defines specific characteristics for the code to use.
In this case, the parameter tells the computer the exact text to display in the alert.
Write your own message that fits your document and shows off your personality.
Save your code.
Then, run it by clicking the play button.
Switch back to the tab for your Research Notes.
There’s the window!
If the alert doesn’t show, or if you see an error message in the Script Editor, check the code carefully.
Check your capitalization.
Look for extra spaces or periods.
And make sure the text of the alert is inside double quotation marks.
If you’ve checked your code and the alert still doesn’t appear or you get an error message, ask your neighbor for help.
They might see an error you missed.
Computer scientists often team up to create and check code.
Sometimes two people working together can find and solve problems faster.
Now, it’s your turn: Type DocumentApp to tell the computer where the prompt will appear.
Use the autocomplete menu to choose the placement and type of message.
Replace the word “prompt” with your unique alert message.
Save and run the code to make the alert appear in your “Research Notes” document Then, click the arrow to move on to the next video.