Q:

Javascript quiz result calculation/generation

I wrote a javascript quiz for my rails app in which there was a choice between only two answers for each question, I'm now trying to scale it up so that there are four questions and four results pages, but haven't been able to get it working so far. Can anybody help? I've tried changing the var calculations but haven't been successful so far. 
function generateResult(answers) {
  var panda = bear = 0;
  for(var i =0; i < answers.length; i++){
    if(answers[i] == 1){
      bear++;
    }
    else {
      panda++;
    }
  }
    if(bear > panda) {
      return "sbear.html";
    }
    else if(bear > elephant) {
      return "sbear.html";
      }
     else if(bear > alpacha) {
      return "sbear.html";
      }

    else if(panda > bear) {
      return "sbear.html";
    }
    else if(panda > elephant) {
      return "sbear.html";
      }
     else if(panda > alpacha) {
      return "rpanda.html";
      }

     else if(alpacha > bear) {
      return "sbear.html";
    }
    else if(alpacha > panda) {
      return "sbear.html";
      }
     else if(alpacha > elephant) {
      return "alpach.html";
      }

    else {
      return "eleph.html"; 
    }
}

A:

I'm not sure these are the right values of bear/panda/elephant/alpac(h)a, but you can swap those in pretty easy. 
function generateResult(answers) {
   // initialize ALL variables
   var panda = bear = elephant = alpacha = 0;
   for(var i =0; i < answers.length; i++){
      if(answers[i] == 1){ // assuming bear == 1
         bear++;
      }
      else if(answers[i] == 2) { // assuming panda == 2
         panda++;
      }
      else if(answers[i] == 3) { // assuming elephant == 3
         elephant++;
      }
      else { // assuming alpacha == 4
         alpacha++;
      }
   }
   if (bear > alpacha && bear > panda && bear > elephant) {
      return "sbear.html";
   }
   else if (alpacha > bear && alpacha > panda && alpacha > elephant) {
      return "alpach.html";
   }
   else if (panda > alpacha && panda > bear && panda > elephant) {
      return "rpanda.html";
   }
   else {
      return "eleph.html";
   }
}

