repository to manage all files for 1_2_oder_3 interaction game for Inf2/2 Interaktionen SoSe23 from Engert, Caliskan and Bachiri
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.js 1.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. let question_var = document.getElementById("question")
  2. let firstanswer_var = document.getElementById("firstquestion")
  3. let secondanswer_var = document.getElementById("secondquestion")
  4. let thirdanswer_var = document.getElementById("thirdanswer")
  5. let nextbutton = document.getElementById("nextbutton")
  6. let startbutton = document.getElementById("startbutton")
  7. let i = 1
  8. let startgame = true
  9. let intervallid;
  10. let secondsleft = 10;
  11. const xhr = new XMLHttpRequest();
  12. const url = "http://127.0.0.1:5555/GETQUESTION";
  13. function ChangeStatus(boolean) {
  14. return boolean !== true;
  15. }
  16. function getQuestion(){
  17. // TODO: MAKE HTTP REQUEST TO GET QUESTION FROM BACKEND
  18. fetch(url)
  19. .then(response => response.json())
  20. .then(data => {
  21. console.log(data);
  22. document.getElementById("question").innerText = data['TEST'];
  23. document.getElementById("firstanswer").innerText = data['firstanswer'];
  24. document.getElementById("secondanswer").innerText = data['secondanswer'];
  25. document.getElementById("thirdanswer").innerText = data['thirdanswer'];
  26. })
  27. .catch(error => console.error(error));
  28. console.log("Question got");
  29. document.getElementById("question").innerText = (i++).toString() + ". Question ";
  30. }
  31. function nextQuestion(){
  32. console.log("nextQuestion clicked")
  33. getQuestion()
  34. secondsleft=10;
  35. timerstart()
  36. }
  37. function startGame() {
  38. startgame = (startgame !== true);
  39. console.log("Button clicked");
  40. if (startgame === false){
  41. }
  42. document.getElementById("nextbutton").style.visibility = "visible";
  43. document.getElementById("startbutton").style.visibility = "hidden";
  44. getQuestion();
  45. timerstart()
  46. }
  47. function timerstart() {
  48. intervallid = setInterval(function() {
  49. document.getElementById('timer').textContent = secondsleft;
  50. if (secondsleft === 0) {
  51. clearInterval(intervallid);
  52. }
  53. secondsleft--;
  54. }, 1000);
  55. }