samedi 12 décembre 2020

How would I organise the answer from the users choice without using a DRY if statement?

I'm making a recommendation application. Where its MCQ with four answers. Now is there a way to make it so the I don't need to make a dry if statement?

So, for example, if the user chooses choice 2 of question 1 && choose choice 4 of question 2 && choose choice 1 of question 3 ... and so on. So based on what the user chooses I make a recommendation accordingly.

var questions = [
    Question(text: "How much do you want to spend tonight?",
             choice1: "$20", choice1Destination: 1,
             choice2: "$30", choice2Destination: 2,
             choice3: "$40", choice3Destination: 3,
             choice4: "$50", choice4Destination: 4),
    
    Question(text: "Where is your optimal location?",
             choice1: "KINGSCROSS", choice1Destination: 1,
             choice2: "DOWNTOWN", choice2Destination: 2,
             choice3: "BONDI", choice3Destination: 3,
             choice4: "BANKSTOWN", choice4Destination: 4),
    
    Question(text: "What do you feel like having?",
             choice1: "SEAFOOD", choice1Destination: 1,
             choice2: "PIZZA", choice2Destination: 2,
             choice3: "CHINESE", choice3Destination: 3,
             choice4: "BURGERS", choice4Destination: 4),
    
    Question(text: "What day do you wish to go?",
             choice1: "MON/TUE", choice1Destination: 1,
             choice2: "WED/THU", choice2Destination: 2,
             choice3: "FRI/SAT", choice3Destination: 3,
             choice4: "SUNDAY", choice4Destination: 4)
    
]

Aucun commentaire:

Enregistrer un commentaire