Skip to content
Snippets Groups Projects
Commit 91833fab authored by romain's avatar romain
Browse files

Récupération info api vers front + résultat

parent 3feb7f54
Branches
No related tags found
No related merge requests found
frontend/1.jpg

3.58 MiB

File moved
frontend/3.jpg

5.84 MiB

...@@ -36,8 +36,9 @@ ...@@ -36,8 +36,9 @@
<body> <body>
<h1> OUCÉQUECÉ</h1> <h1> OUCÉQUECÉ</h1>
<h2><img src="perpignan-france.jpg" alt="perpignan" width=50% height=50% /></h2> <h2><img id="img" src="" width=50% height=50% /></h2>
<h3 id="test"></h3> <h3 id="test"></h3>
<h4 id="resultat"></h4>
<div id="a1" class="rectangle-arrondi" data-index="1"></div> <div id="a1" class="rectangle-arrondi" data-index="1"></div>
<div id="a2" class="rectangle-arrondi" data-index="2"></div> <div id="a2" class="rectangle-arrondi" data-index="2"></div>
...@@ -52,12 +53,14 @@ ...@@ -52,12 +53,14 @@
const question=JSON.parse(data.question); const question=JSON.parse(data.question);
const vraiquestion=question.question; const vraiquestion=question.question;
const reponse=question.answers; const reponse=question.answers;
const img=data.imageIndex const img=question.imageIndex;
document.getElementById("test").innerText = vraiquestion; document.getElementById("test").innerText = vraiquestion;
document.getElementById("a1").innerText = reponse[0]; document.getElementById("a1").innerText = reponse[0];
document.getElementById("a2").innerText = reponse[1]; document.getElementById("a2").innerText = reponse[1];
document.getElementById("a3").innerText = reponse[2]; document.getElementById("a3").innerText = reponse[2];
document.getElementById("a4").innerText = reponse[3]; document.getElementById("a4").innerText = reponse[3];
document.getElementById("img").src=img+".jpg";
document.querySelectorAll(".rectangle-arrondi").forEach(div => { document.querySelectorAll(".rectangle-arrondi").forEach(div => {
div.addEventListener("click", async function () { div.addEventListener("click", async function () {
...@@ -81,7 +84,16 @@ ...@@ -81,7 +84,16 @@
} }
const responsejson2 = await response2.json(); const responsejson2 = await response2.json();
document.getElementById("test").innerText = JSON.stringify(responsejson2); const resp = JSON.stringify(responsejson2)
const vrairesp= JSON.parse(resp);
if (vrairesp.answer==false){
document.getElementById("resultat").innerText = "Faux c'était " + vrairesp.correctAnswer + "score : "+ vrairesp.score;
next();
}
if (vrairesp.answer==true){
document.getElementById("resultat").innerText ="Bien joué ! score : "+ vrairesp.score;
next();
}
} catch (error) { } catch (error) {
...@@ -90,6 +102,38 @@ ...@@ -90,6 +102,38 @@
}); });
}); });
async function next() {
const jsonData3 = {
"uuid": uuid
};
try {
const response3 = await fetch("http://localhost:8080/projet_prog_reseau_war_exploded/api/quiz", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(jsonData3),
});
if (!response3.ok) {
throw new Error(`Erreur HTTP : ${response3.status}`);
}
const responsejson3 = await response3.json();
const newresp = JSON.stringify(responsejson3)
const newquestions= JSON.parse(newresp);
const reponse=newquestions.answers;
const img=newquestions.imageIndex;
document.getElementById("a1").innerText = reponse[0];
document.getElementById("a2").innerText = reponse[1];
document.getElementById("a3").innerText = reponse[2];
document.getElementById("a4").innerText = reponse[3];
document.getElementById("img").src=img+".jpg";
} catch (error) {
console.error("Erreur : ", error);
}
}
</script> </script>
</html> </html>
\ No newline at end of file
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
cursor: pointer; cursor: pointer;
width : 175px; width : 175px;
height: 70px; height: 70px;
font-size: 15; font-size: 15px;
margin-left: 260px; margin-left: 260px;
} }
......
...@@ -5,27 +5,28 @@ ...@@ -5,27 +5,28 @@
"Paris", "Paris",
"Lyon", "Lyon",
"Bordeaux", "Bordeaux",
"Montpellir" "Montpellier"
], ],
"correctAnswer": 3 "correctAnswer": 4
}, },
{ {
"imageIndex": 2, "imageIndex": 2,
"answers": [ "answers": [
"lul", "Pekin",
"Ldsn", "Tokyo",
"Bofsfsux", "Shangai",
"Monfqfqlier" "Nagasaki"
], ],
"correctAnswer": 2 "correctAnswer": 2
}, },
{ {
"imageIndex": 2, "imageIndex": 3,
"answers": [ "answers": [
"lufsfs", "New york",
"Ldsn", "Londre",
"Bofsfsfsfsfsfs", "Montreal",
"Mpapappaqlier" "Nice"
], ],
"correctAnswer": 2, "correctAnswer": 3
}
] ]
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment