1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- let question_var = document.getElementById("question")
- let firstanswer_var = document.getElementById("firstquestion")
- let secondanswer_var = document.getElementById("secondquestion")
- let thirdanswer_var = document.getElementById("thirdanswer")
- let nextbutton = document.getElementById("nextbutton")
- let startbutton = document.getElementById("startbutton")
- let i = 1
- let startgame = true
- let intervallid;
- let secondsleft = 10;
- const xhr = new XMLHttpRequest();
- const url = "http://127.0.0.1:5555/GETQUESTION";
-
- function ChangeStatus(boolean) {
- return boolean !== true;
- }
-
- function getQuestion(){
- // TODO: MAKE HTTP REQUEST TO GET QUESTION FROM BACKEND
- fetch(url)
- .then(response => response.json())
- .then(data => {
- console.log(data);
- document.getElementById("question").innerText = data['TEST'];
- document.getElementById("firstanswer").innerText = data['firstanswer'];
- document.getElementById("secondanswer").innerText = data['secondanswer'];
- document.getElementById("thirdanswer").innerText = data['thirdanswer'];
-
-
- })
- .catch(error => console.error(error));
-
- console.log("Question got");
- document.getElementById("question").innerText = (i++).toString() + ". Question ";
- }
-
- function nextQuestion(){
- console.log("nextQuestion clicked")
- getQuestion()
- secondsleft=10;
- timerstart()
- }
- function startGame() {
- startgame = (startgame !== true);
- console.log("Button clicked");
- if (startgame === false){
- }
- document.getElementById("nextbutton").style.visibility = "visible";
- document.getElementById("startbutton").style.visibility = "hidden";
- getQuestion();
- timerstart()
- }
-
- function timerstart() {
- intervallid = setInterval(function() {
- document.getElementById('timer').textContent = secondsleft;
- if (secondsleft === 0) {
- clearInterval(intervallid);
- }
- secondsleft--;
- }, 1000);
- }
|