From c4cdd44846bdf6ce426010b248365c536710e33a Mon Sep 17 00:00:00 2001 From: joniboy74prog Date: Fri, 8 Dec 2023 04:41:02 +0100 Subject: [PATCH] nouvelle fonction correcte --- .vscode/settings.json | 3 -- back/fonctions.js | 15 ++++++- back/indextest.html | 2 +- back/script.js | 89 ----------------------------------------- front/.idea/.gitignore | 5 --- front/.idea/discord.xml | 7 ---- front/.idea/front.iml | 12 ------ front/.idea/misc.xml | 6 --- front/.idea/modules.xml | 8 ---- front/.idea/vcs.xml | 6 --- 10 files changed, 14 insertions(+), 139 deletions(-) delete mode 100644 .vscode/settings.json delete mode 100644 back/script.js delete mode 100644 front/.idea/.gitignore delete mode 100644 front/.idea/discord.xml delete mode 100644 front/.idea/front.iml delete mode 100644 front/.idea/misc.xml delete mode 100644 front/.idea/modules.xml delete mode 100644 front/.idea/vcs.xml diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index 6f3a291..0000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "liveServer.settings.port": 5501 -} \ No newline at end of file diff --git a/back/fonctions.js b/back/fonctions.js index 45bf103..b7fece7 100644 --- a/back/fonctions.js +++ b/back/fonctions.js @@ -156,8 +156,19 @@ function getImg2(categorie, indice){ // function for random index of a function - function getIndex(){ - + function getIndex(tableauDentiers){ + if (tableauDentiers.length == 0){ + return -1; + } + const indiceAleatoire = Math.floor(Math.random() * tableauDentiers.length); + tableauDentiers.splice(indiceAleatoire, 1); + console.log(tableauDentiers); // Affiche : [1, 2, 4, 5] + return indiceAleatoire; } + document.addEventListener('DOMContentLoaded', ()=> + { + const tableauDentiers = [1, 2, 3, 4, 5]; + } + ) diff --git a/back/indextest.html b/back/indextest.html index ccd28e9..d3592a8 100644 --- a/back/indextest.html +++ b/back/indextest.html @@ -6,6 +6,6 @@ - + \ No newline at end of file diff --git a/back/script.js b/back/script.js deleted file mode 100644 index f7072b4..0000000 --- a/back/script.js +++ /dev/null @@ -1,89 +0,0 @@ - -function fonction_marrante() {// Charger le contenu du fichier JSON - fetch('./resources/Commerce.json') - .then(response => { - if (!response.ok) { - throw new Error(`Erreur de chargement du fichier JSON : ${response.status}`); - } - return response.json(); - }) - .then(objetJson => { - // Accéder au tableau 'questions' dans l'objet JSON - const questions = objetJson.questions; - - // Afficher chaque question dans la console - questions.forEach(question => { - console.log(question.question); - }); - - alert('Questions chargées avec succès. Consultez la console pour les détails.'); - }) - .catch(erreur => { - console.error('Erreur lors du chargement du fichier JSON :', erreur.message); - alert('Erreur lors du chargement du fichier JSON. Consultez la console pour les détails.'); - }); -} - - -// retourne random index - -async function getQuestionByCategorie2(category) { - try { - const response = await fetch(`./${category}.json`); - - if (!response.ok) { - throw new Error(`Erreur de chargement du fichier JSON : ${response.status}`); - } - - const objetJson = await response.json(); - const questions = objetJson.questions; - - console.log(questions); - return questions; - - } catch (error) { - console.error('Erreur lors du chargement du fichier JSON :', error.message); - alert('Erreur lors du chargement du fichier JSON. Consultez la console pour les détails.'); - throw error; // Re-throw the error for further handling - } - } - - - console.log(getQuestionByCategorie2("transport")) - - function shuffleArray(array) { - const shuffledArray = [...array]; - for (let i = shuffledArray.length - 1; i > 0; i--) { - const j = Math.floor(Math.random() * (i + 1)); - [shuffledArray[i], shuffledArray[j]] = [shuffledArray[j], shuffledArray[i]]; - } - return shuffledArray; - } - - function createShuffledIndicesArray(array) { - const indicesArray = Array.from({ length: array.length }, (_, index) => index); - return shuffleArray(indicesArray); - } - - function getNextIndex(indicesArray) { - if (indicesArray.length === 0) { - // Si tous les indices ont été utilisés, réinitialiser le tableau d'indices - return null; // ou une autre valeur pour indiquer que tous les indices ont été utilisés - } - // Retourner et retirer le premier indice du tableau - return indicesArray.shift(); - } - - // Utilisez ces fonctions comme suit : - - // const votreTableau = ["Item 1", "Item 2", "Item 3", "Item 4", "Item 5"]; - const votreTableau = await getQuestionByCategorie2('transport'); - const shuffledIndices = createShuffledIndicesArray(votreTableau); - - // À chaque appel, récupérez le prochain indice - const premierIndice = getNextIndex(shuffledIndices); - const deuxiemeIndice = getNextIndex(shuffledIndices); - - console.log(premierIndice); // Indice aléatoire - console.log(deuxiemeIndice); // Indice différent - diff --git a/front/.idea/.gitignore b/front/.idea/.gitignore deleted file mode 100644 index b58b603..0000000 --- a/front/.idea/.gitignore +++ /dev/null @@ -1,5 +0,0 @@ -# Default ignored files -/shelf/ -/workspace.xml -# Editor-based HTTP Client requests -/httpRequests/ diff --git a/front/.idea/discord.xml b/front/.idea/discord.xml deleted file mode 100644 index 30bab2a..0000000 --- a/front/.idea/discord.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - \ No newline at end of file diff --git a/front/.idea/front.iml b/front/.idea/front.iml deleted file mode 100644 index 24643cc..0000000 --- a/front/.idea/front.iml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - - - - - - \ No newline at end of file diff --git a/front/.idea/misc.xml b/front/.idea/misc.xml deleted file mode 100644 index 3ce3588..0000000 --- a/front/.idea/misc.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - \ No newline at end of file diff --git a/front/.idea/modules.xml b/front/.idea/modules.xml deleted file mode 100644 index a3b5ecf..0000000 --- a/front/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/front/.idea/vcs.xml b/front/.idea/vcs.xml deleted file mode 100644 index 6c0b863..0000000 --- a/front/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file