Last active
August 10, 2023 02:10
-
-
Save kenresoft/48af1501b30acbf49e19944e6384fc18 to your computer and use it in GitHub Desktop.
A function that returns the color of an option based on whether the option is correct and whether the option is selected.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void main(List<String> arguments) { | |
options = ['Multiply', 'Dart', 'Function', 'Gold', 'Silver', 'Bronze']; | |
String getColorForOption(String answer) { | |
bool correctAnswer = answer.startsWith("S"); | |
bool isSelected = answer.startsWith("D"); | |
if (isSelected) { | |
return correctAnswer ? 'Green' : 'Red'; | |
} else { | |
return correctAnswer ? 'Green-Correction' : 'Grey'; | |
} | |
} | |
for (var answer in options) { | |
print(getColorForOption(item)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Output
Grey
Red
Grey
Grey
Green-Correction
Grey