Advertisement
Isoraqathedh

maxScoreFinder

Dec 19th, 2016
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Replace this...
  2. var out = "mt-aether";
  3. i = aether;
  4. if (item > i) { out = "mt-item"; i = item; }
  5. if (glyph > i) { out = "mt-glyph"; i = glyph; }
  6. if (potion > i) { out = "mt-potion"; i = potion; }
  7. if (incantation > i) { out = "mt-incantation"; i = incantation; }
  8.  
  9. // with this:
  10. var out = resultPage(
  11.     [aether, item, glyph, potion, incantation],
  12.     ["mt-aether", "mt-item", "mt-glyph", "mt-potion", "mt-incantation"])
  13.  
  14.  
  15. // and place this into quiz-question-engine.js:
  16. function resultPage(scoreArray, pageNames) {
  17.     // Find the page that corresponds to the largest score.
  18.     // If multiple pages have the same score, then choose the leftmost one.
  19.     var runningTotal = -Number.MAX_VALUE;
  20.     var runningTotalIndex = 0;
  21.     for (var i in scoreArray) {
  22.         if (scoreArray[i] > runningTotal) {
  23.             runningTotal = scoreArray[i];
  24.             runningTotalIndex = i;}}
  25.     return pageNames[runningTotalIndex];}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement