Skip to content

Instantly share code, notes, and snippets.

@mariohmol
Last active March 10, 2017 21:30
Show Gist options
  • Save mariohmol/f47c29c7f9a0e7b15979eecd60a004e4 to your computer and use it in GitHub Desktop.
Save mariohmol/f47c29c7f9a0e7b15979eecd60a004e4 to your computer and use it in GitHub Desktop.
var breeds={'chiuauahua': 0, 'bull terrier': 0, 'bulldog': 0, 'boxer': 0}
var questions = [
{
question: "1. What size you like?",
answers: ["small","big"],
results: { "small":["chiuauahua",'bull terrier'] , "big": ['bulldog','boxer'] }
},
{
question: "2. Are u alergic?",
answers: ["small","big"],
results: { "small":["chiuauahua",'bull terrier'] , "big": ['bulldog','boxer'] }
},
];
var currentQuestion = questions[0];
userAnswer="small"
breedsResults = currentQuestion.results[userAnswer];
for(i in breedsResults){
breeds[i]++;
}
/*
if(answer=="small"){
breeds['chiuauahua']++;
breeds['bull terrier']++;
}
else if(answer=="big"){
breeds['bulldog']++;
breeds['boxer']++;
}*/
//at the end get the key that has the greatest value
max=0;
maxBreed=null;
for(breed in breeds){
if(breeds[breed]>max){
max=breeds[breed];
maxBreed=breed;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment