I have a student who wants to create an app in which the buttons are selected to make choices and screens are set depending on which buttons were selected from a series of screens. For example screen one has a choice of a button called “yellow” or a button called “white”, screen two has “solid” or “print”. If the user chooses “yellow” and “solid” that would go to screen 3, if they choose “yellow” and “print” that would go to screen 4, if they chose “white” and “solid” then screen 5 and “white” and “print” then it would go to screen 6. Please help. Thanks!
you could setup an array that tracks choices and appends the item
var choices = [];
// add this in an event where you wish to store the information
choices[0] = "yellow";
then you can refer to the users choices within this global array following the decisions made by the user the [0]
is the index you can add any valid positive integers to store more choices this way, of course there are more ways of doing it, but this would probably be the easiest since your storing user choices/preferences
Thanks! That was a bit confusing for me but Chat GPT helped me out and had me do this code which worked!
onEvent(“yellow”, “click”, function( ) {
setScreen(“screen2”);
});
onEvent(“white”, “click”, function( ) {
setScreen(“screen2”);
});
var colorChoice;
var patternChoice;
// First Screen - Color Selection
onEvent(“yellow”, “click”, function() {
colorChoice = “yellow”;
});
onEvent(“white”, “click”, function() {
colorChoice = “white”;
});
// Second Screen - Pattern Selection
onEvent(“solid”, “click”, function() {
patternChoice = “solid”;
checkChoices();
});
onEvent(“print”, “click”, function() {
patternChoice = “print”;
checkChoices();
});
function checkChoices() {
if (colorChoice == “yellow” && patternChoice == “solid”) {
setScreen(“screen5”);
} else if (colorChoice == “yellow” && patternChoice == “print”) {
setScreen(“screen6”);
} else if (colorChoice == “white” && patternChoice == “solid”) {
setScreen(“screen4”);
} else if (colorChoice == “white” && patternChoice == “print”) {
setScreen(“screen3”);
}
}