Newer
Older
AEDmap2023 / quiz.js
@菅原綾乃 菅原綾乃 on 31 Oct 2023 875 bytes Update quiz.js
(() => {
  var quiz = [],
nQuiz,
pos=0;	
  var csvfile = "R5AED.json";	
  function putValues(row) {
for (let key of Object.keys(row)) {
    let id = "__" + key + "__"; 
    let elem = document.getElementById(id);
    if (elem) {  
  elem.innerText = row[key]; 
    }
}
  }
  
  
 function slide(n) {	
pos = (nQuiz+pos+n) % nQuiz;	
putValues(quiz[pos]);		
  }
  function left() {slide(-1);}	  
  function right() {slide(1);}	
  function init() {			
fetch(csvfile).			
    then((resp) => {		
  if (resp.ok) return resp.text();	
    }).then((txt) => {		
  quiz = new CSV(txt, {header: true}).parse(); 
  nQuiz = quiz.length;	
  putValues(quiz[pos]);	
    });;
document.getElementById("left").addEventListener("click", left);
document.getElementById("right").addEventListener("click", right);
  }
  document.addEventListener("DOMContentLoaded", ()=>{
init();	
  }, false);
})();