U4Ch1L8_ Level2_ Conditionals _ Make Purpose: Students will apply their skills in order to rewrite Conditional Statements.
Activity: Build This App! Based on the Skills You Learned!
Step #1: Run the Program!
Journal: Answer the following Questions:
Look at the App…what are some of the necessary components required to build the interface of this App? Answer
All the skills required to build this App come from Apps you have already built. Which previous lesson (Levels), did you learn the skills necessary to build this App. Note: Look back at the previous lessons to see where you have programmed parts of Apps that you will have to recreate here. When you find something close, copy, paste and edit the lines of code to match this new App that you are building!Answer
The ‘onEvent’ clicked button.
The Input String/text dropdown menu.
The Input Number dropdown menu.
The Discount Entry Form Field.
The Output Screen
Step #2: Create a Flowchart of How This Program Will Run.
Your Flowchart should contain geometric shapes, arrows, and text. (Remember, A flowchart is not a Program! A Flowchart is just a visual as to how the program should flow.) My Example.
Step #3: Open Level2!!
Begin writing your program in Level 2!
Go copy the lines of code from the programs you have previously written (mine are mentioned above) and paste them into this program and edit them so they will work in this program.
Here is the order in which I entered my code:
Create Variables
var day, age, price, discountCode, ticketText.
onEvent/button/click
Update Variables
day = getText
age = getNumber
discountCode = getText
Begin ‘if-else’ statements. Begin with the Most Specific, in this program the most specific is the Discount Code Entry (look at your Flowchart).
Check if they're using the FREEFRIDAY code on a Friday.
I wrote this as: if discountCode equals FREEFRIDAY AND day equals Friday, then price is ‘0’.
Hint: Copy the ‘like’ code from Step #1 above for if-else, paste it into this App and make the edits.
Next write the Code to Check if it's a Weekend. Everyone pays full price on weekends.
I wrote this as: ‘else-if’ ‘day ‘equals ‘Saturday’ OR ‘day’ equals ‘Sunday’, then the price equals ‘10’.
Hint: Copy the ‘like’ code from Step #1 above for if-else, paste it into this App and make the edits.
Next write the Code to Check if it's a Child. You've already checked if it's a weekday so there's no need to check the day. Just write the code to check if they're a child.
I wrote this as: else if ‘age’ is less than or equal to ‘18’ then the ‘price’ should be ‘5.’
Hint: Copy the ‘like’ code from Step #1 above for if-else, paste it into this App and make the edits.
Finally, if none of the conditions above apply, then the ‘if-else’ section ends with an ‘else’ statement:
I wrote this as: ‘price’ equals ‘10’
Now let’s generate the Message to be seen on the ‘Display’ - I am giving it to you!
I wrote this as: ticketText = “Day: “ + day + “\nAge: “ + age. + “n\Price: $” + price ;