Skip to content

Instantly share code, notes, and snippets.

@kenresoft
Last active August 10, 2023 02:10
A function that returns the color of an option based on whether the option is correct and whether the option is selected.
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));
}
}
@kenresoft
Copy link
Author

Output

Grey
Red
Grey
Grey
Green-Correction
Grey

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment