1_2_oder_3_repos/src_folder/FrontEnd/index.js
2023-05-12 08:44:00 +02:00

62 lines
1.9 KiB
JavaScript

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);
}