Unit 4 Lesson 11
Name(s)____Amanda and Isabella___________________________________________ Period ______ Date
___________________
Activity Guide - Functions Make
Step 1 - Try the app
● Try many of the different options.
● Pay attention to what is happening on the screen
when you move the slider or choose an item from the
dropdown.
● When does the screen update?
● What happens if you choose lavender and Lucida
Sans from the dropdowns? Try choosing lightgreen
and moving the slider until you receive feedback.
Come up with answers to following questions (no need to
answer them here)
● What does this app do?
● What are the inputs?
● What are the outputs?
● How could a function be used in this app?
Step 2 - Plan
Decide if you will work with a partner or alone. If you work with a partner write the person’s name here: Isabella
Variables: Fill in the table below for each variable you'll need to create.
Variable Name What the Variable Stores
color the background color the user selects
fontFamily The font for the quote that the user selects
quote whatever string of characters the user inputs
fontSize The size that the user chooses to have the chosen font displayed at
Conditionals: An if-else-if statement is used to check if certain options have been selected. Set up the conditional
below using the variables you created above.
● Note: You can be creative here! Choose your own combinations and feedback messages.
if (color == _”lightyellow”______________ && fontFamily == __”Courier”__){
setText("feedbackOutput", _______” Nice Design!”____________);
} else if ( _____colour_______ == ______” lavender”____ && ____fontSize_____ == ___22_____ ){
setText("feedbackOutput", ______” Lovely Selection!”____);
} else {
setText("feedbackOutput", ___”Best yet!”___________________________);
}
Computer Science Principles 1
Unit 4 Lesson 11
Functions: Consider what should be included in a function that updates the screen. Write out your plan below.
Things to think about:
● What elements on the screen need to be updated using the variables above?
● Does the conditional above belong in the function? Why or why not?
● When will the function be called?
Every time an input is changed, the text box Review the updateScreen() Pattern to help you plan
on the screen must be updated. The color, your function.
font, size, and text must all be changed. The
above conditional belongs within the function
that changes the screen if one of the specific
combinations is set. When an input is
changed, the function is called.
Inputs: What are the inputs for the app? These will all be turned into onEvents.
Input Action Result
"quoteInput" keyup The text on the screen appears, one character at a time as it's typed.
"fontFamilyInput" change The text will be replaced with a different font from the font family
drop-down menu.
“colorInput” change The previously gray screen will now be the color chosen from the color
drop-down menu.
“fontSizeInput” input As the user moves the slider the font will change size.
Computer Science Principles 2
Unit 4 Lesson 11
Step 3 - Write Your Code
● Write the code for the app, using your plan above and the comments provided in Code Studio to help
● Step You Can Follow
○ Create all the variables from your table above.
○ Give your variables a starting value using the assignment operator (=)
○ Create a conditional that checks if various options are selected.
○ Create a function that updates the screen.
○ Create event handlers (onEvent) for the inputs in your table above
○ Use your debugging skills to identify unexpected behavior and fix your program
○ Comment your code as you go, explaining what each event handler and function does
● Extension Ideas
○ Create a dropdown with image names and decorate your quote!
Step 4 - Submit
Before you submit, check the rubric below to make sure your program meets the requirements of the task.
Category Extensive Evidence Convincing Limited Evidence No Evidence
4 Evidence 2.5 1 0
Input onEvents are onEvents are onEvents are onEvents are not
created for all the created for most of created for some of created for any
required inputs. the inputs. the inputs. inputs.
Storage: Variables Variables are created Most information is Some information is There are no
and appropriately stored in a variable stored in a variable variables which store
used for all pieces of and appropriately and appropriately the necessary
information used in updated throughout updated throughout information for the
the app. the app. the app. app to work correctly.
Code: Conditionals An if-else-if An if-else-if An if-else statement No conditional is
statement is used statement is used or an if statement is present.
which correctly that partially checks used that checks if
checks if certain if certain options one option has been
options have been have been selected selected.
selected and and displays
displays feedback. feedback.
Code: Functions A function is used A function is used A function is used There is no function
which correctly which correctly which updates some which updates the
updates all output updates most of the of the output screen.
elements. The output elements. The elements or the
function is called in function is called in function is only
all onEvents. all onEvents. called in some
onEvents.
Code runs without No errors are One or two errors Three or four errors More than four errors
errors. present in the are present in the are present in the are present in the
required code. required code. required code. required code.
Coding Comments Comments are used Comments are used Comments are used Comments are not
to correctly explain to explain the to explain the present.
the purpose and purpose and function purpose and function
function of all of most onEvents of some onEvents
onEvents and and functions. and functions.
functions.
Computer Science Principles 3