View Single Post
Old 02-05-2013, 02:43 AM   PM User | #6
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,244
Thanks: 59
Thanked 3,998 Times in 3,967 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
I'd be seriously tempted to reorganize this.

Will the answer for "closest match" (to the 3 answers) be coming from a DB query? That is, using AJAX or similar? Or will you hard code the matches in the JavaScript?

If you are going to hard cold the matches, I'd be tempted to do it thus:
Code:
var choices = {
    "sour" : { 
        "cold" : { 
            "good" : "diet limeade",
            "bad" : "sour lemon slushee"
            },
        "warm" : {
            "good" : "fresh sour cherries",
            "bad" : "sour lemon candies"
            }
        "hot" : {
            "good" : "hot and sour soup",
            "bad" : "chili relleno"
        },
        "burning" : {
            "good" : "fresh jalapeno pepper",
            "bad"   : "fresh jalapeno pepper" /*joke*/
       }
    "bland" : {
        "cold" : {
            "good" : ... etc ...
You see that? Then to find the product you only have to do:
Code:
    var product = choices[userTasteChoice][userTempChoice][userGoodBadChoice];
But clearly that could get tedious for lots of choices, so I'd hope you are really going to do this via a DB and AJAX?
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is online now   Reply With Quote