Skip to content
Playback Speed:
Transcript

In this video, you will write the config part of your code.

If you do not know which part of the code you are responsible for, check with your group members.

Only watch the videos necessary to write your part of the code.

This function adds the movie poster URLs and the name of the movie poster to the website.

You will also write a function to help select a random poster.

To write the config code, you will : Create a posters variable that holds the names and URLs of each movie poster.

Write a function to select one of the posters randomly.

To start, select the “config dot gs file.”

Then, create a variable to hold the name and URL of each poster.

Type: v-a-r, posters, equals, open bracket.

Then, press Enter several times to create a space for the URLs.

Close the bracket and close the statement with a semicolon Within the posters variable, add an object to hold each poster name and URL.

Objects let you store related information together.

First, type an open curly brace, the letters u-r-l, a colon, a space, two single quotation marks, and a comma.

Type a space, the word “name,” a colon, a space, two single quotation marks.

Then, type a closed curly brace and a comma.

Then, copy and paste the line two more times so you have a total of three objects, one for each poster.

Remove the comma from the third line.

Next, get the exact URL for each movie poster.

To do this, go to Google Drive.

The posters may be in your Shared with Me drive.

Right click to open a preview of the image.

Hold the control key and right-click the image.

Select “Open image in new tab.”

Copy the URL from the address bar and paste it into your code between the two single quotation marks.

Next, add a name for the poster object that identifies the poster’s designer.

Make sure each name is unique and does not contain any punctuation.

This is the name that will identify the poster in your spreadsheet, so be sure to give each poster a recognizable name.

Repeat the same steps for each movie poster.

Preview the image.

Open it in a new tab.

Copy and paste the URL into the code, and give it a unique name.

Great job!

At this point, you have created a poster variable to hold the URLs and names of each of your posters.

Next, write a function to select one of the posters randomly.

Underneath the posters variable and after the last closed bracket, start a new line of code.

Type the following exactly as you see it on the screen: function, space, choosePosterNumber, open parentheses, close parentheses, open curly brace.

Then, press the Enter key, and a closed curly brace.

The “render” section of the code, which your partner is writing, will call this function.

Now, tell the computer to return a random whole number between 0 and 2.

Each number corresponds to one of the objects in the posters variable.

The number zero is the first poster, number 1 the second, and so on.

After the first curly brace, type: return, space, Math, dot.

An autofill menu appears.

Select “round” from the menu.

This will make sure that the computer chooses a whole number instead of a decimal or a zero.

Inside the parentheses, replace the “X” with “Math dot” This time, select “Random” from the autofill menu.

After the first set of parentheses, type: space, asterisk, space 2.

Add a semicolon at the end of the line to close this statement.

Check to be sure your code looks exactly like what is on the screen.

Terrific!

Next, try running your program.

Save it, select “choosePosterNumber” and click “run.”

Give permission to publish your web page.

Great!

Next, run a test to ensure your code will work well with the other code files.

Tests are separate programs used to test sections of code.

Open “tests dot gs” from the script editor sidebar.

Select the test posters function and run the code.

Then, check the code log.

See if the program returns any errors.

In this example, it does not.

Great!

If the log returns an error message like “You haven’t created a variable named posters yet,” go back to the config file and check your code carefully.

If you need help, ask a neighbor or your teacher.

Once you have finished writing the "config dot gs code," check on your group members and see if they need help.

Then, when you are all ready, move on to the next video to publish your group’s code.

Now, it’s your turn: Create a posters variable to hold the URL and name of your posters.

Add objects for all three posters in your variable, including name and URL.

Write a function to select one of the posters randomly.

And finally, test your program using the poster test function in the "test dot gs file."

When everyone in your group is finished writing their piece of the code, move on to next video to publish your website.

Next arrow_forward
Instructions
  1. Create a posters variable to hold the URL and name of your posters.
  2. Add objects for all three posters in your variable, including name and URL.
  3. Write a function to select one of the posters randomly.
  4. Test your program using the poster test function in the test.gs file.
  5. When everyone in your group is finished writing their piece of the code, move on to next video to publish your website.