Lesson 15 - Surprise Emoji

Learning outcomes:

  • Randomness: your students will learn how to randomize data with math!

Your students Accomplish:

  • Making their own custom video filter as they learn a real programming language.


Surprise Emoji - Unit 2, Activity 7

Big Idea: Randomness is a mathematical surprise, and it's important.

About the Activity

Access the Math library to pick a random emoji from an array to embellish your video.


CCSS.MATH.PRACTICE.MP2 Reason abstractly and quantitatively.

NGSS ETS1.B: Developing Possible Solutions

CSTA 1B-AP-09 Create programs that use variables to store and modify data.

CSTA 1B-AP-11 Decompose (break down) problems into smaller, manageable subproblems to facilitate the program development process.

CSTA 1B-AP-15 Test and debug (identify and fix errors) a program or algorithm to ensure it runs as intended.

CSTA 1B-AP-16 Take on varying roles, with teacher guidance, when collaborating with peers during the design, implementation, and review stages of program development.

CSTA 1B-AP-17 Describe choices made during program development using code comments, presentations, and demonstrations.

Time: 30 minutes

  • 5 minutes background

  • 20 minutes coding

  • 5 minutes sharing


Review: What is a variable? How do we make one? How do we change it later?

Review: What is an array? How do we access the items in an array?

Discuss: What does "random" mean to you? When do you use randomness in your life? How is randomness like a surprise? (you can't predict it)

In code, randomness is extremely valuable, but because computers are all about patterns, picking a truly random number is actually very difficult. There are people whose job it is to work on inventing better and better functions to choose random numbers. Luckily, you don't have to write one yourself-- you can use JavaScript's Math library.

Every truly random number is completely independent from the last. That means you can't use your knowledge about past choices to predict the future. There is a hugely important industry based on not being able to predict or guess things: security. For password or encryption protocol to be properly secure, it has to be unguessable, or random.

Code Challenge

Students are going to put a random sticker on their video that changes every time the video restarts. Make sure they can access emojis through the internet, or their browser menu. Remind them of school policy on appropriate images.

Have the students complete the "Surprise Emoji" tutorial. Circulate to make sure they understand the directions and are moving forward.

Note: Math is capitalized!

Sample Solution



Play all the completed projects on students' screens, then have the class walk around to view them all. Optional: leave praise and comments on sticky notes.


Compare your project with a partner's. Did you use different emojis? Try combining your lists to have even more to choose from. The more emojis you have in your array, the less likely you will predict which one comes next!


  • What is randomness? (something you can't predict)

  • Sometimes the computer picks the same number twice in a row. Is that random? (Yes. If you know from seeing the last one what the next one isn't, that would help you predict!)

  • Why is randomness valuable? (They use it for security and encryption)

  • Why is randomness difficult? (You have to make sure there are no patterns)