Basically I want to show a particular div depending on which divs are already visible. To make it easier to understand: divs 1,2 represent 'ticks', divs 4,5 represent 'crosses' and div 3 represents 'Correct Answer'. So, if divs 1 and 2 are visible, I want to hide all other divs including 1,2 but show div 3. Similarly, if divs 2,1 are visible, all other divs should be hidden including 1,2 but div 3 should be visible.
So, I realised I was essentially checking the Permutations of divs [1,2] before showing div 3. This is the following behaviour, which works:
function checkAnswer(){
if($("#div1").is(":visible")) {
if($("#div2").is(":visible")){
$("#div1, #div2, #div4, #div5").hide();
$("#div3").show();
}
}
if($("#div2").is(":visible")){
if($("#div1").is(":visible")){
$("#div1, #div2, #div4, #div5").hide();
$("#div3").show();
}
}
if($("#div3").is(":visible")){
$("#div1, #div2, #div4, #div5").hide();
}
}
But if I have a scenario where I have to check for- say 4 divs, it becomes a huge task to keep writing it this way. For example:
function checkAnswer2(){
if($("#div6").is(":visible")) {
if($("#div7").is(":visible")){
if($("#div9").is(":visible")){
if($("#div10").is(":visible")){
$("#div6, #div7, #div9, #div10, #div11").hide();
$("#div8").show();
}
}
}
}
if($("#div6").is(":visible")) {
if($("#div7").is(":visible")){
if($("#div10").is(":visible")){
if($("#div9").is(":visible")){
$("#div6, #div7, #div9, #div10, #div11").hide();
$("#div8").show();
}
}
}
}
//going uptil....
if($("#div8").is(":visible")){
$("#div6, #div7, #div9, #div10, #div11").hide();
}
}
Obviously I haven't mentioned all 24 permutations here of divs[6,7,9,10]
Permutations in javascript can be calculated as explained here: Permutations in JavaScript?
Can it be incorporated in this scenario too using javascript/jquery?
Thanks for all your answers in advance. Any help would be much appreciated.