Computers are good at making decisions. They can do something based on the state you are from, by your age, and any other information that distinguishes one person form another or one product from another.
Here is a code snippet that makes a simple decision.
Here is a code snippet that makes a simple decision.
What does the code do?
This code is written in Block from trinket.io. The code asks the user what city he/she is from. If the user types Boston, the code displays the message, “The Boston Red Sox are your favorite baseball team." If the user types any city but Boston, the code displays, “You like another team.”
How does the code work?
The code begins by displaying the text “What city are you from?" and saves the user’s answer in the variable myCity.
This code is written in Block from trinket.io. The code asks the user what city he/she is from. If the user types Boston, the code displays the message, “The Boston Red Sox are your favorite baseball team." If the user types any city but Boston, the code displays, “You like another team.”
How does the code work?
The code begins by displaying the text “What city are you from?" and saves the user’s answer in the variable myCity.
The code checks to see if the user entered Boston. If the user did, the code displays the text, “The Boston Red Sox are your favorite baseball team.”
If no, if the user typed in a city other than Boston, the code displays the message, “You like another team.