Skip to content

Commit

Permalink
se le agrego mas data al archivo Json para que sea mas largo el juego
Browse files Browse the repository at this point in the history
  • Loading branch information
GermanDelosSantos committed Nov 12, 2023
1 parent b9b52e2 commit 0e64f4e
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 37 deletions.
27 changes: 26 additions & 1 deletion js/preguntasJson.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,30 @@
"question": "¿Cuál es el Pokémon legendario que representa el tiempo?",
"option": ["a) Dialga", "b) Palkia", "c) Giratina"],
"correctAnswer": 0
},
{
"question": "¿Cuál es el Pokémon que puede megaevolucionar en las dos versiones X e Y, pero con megaevoluciones diferentes en cada una?",
"option": ["a) Charizard", "b) Mewtwo", "c) Lucario"],
"correctAnswer": 1
},
{
"question": "¿Cuál es el Pokémon que tiene la habilidad 'Levitón' y es inmune a todos los ataques de tipo Tierra?",
"option": ["a) Gengar", "b) Flygon", "c) Magnezone"],
"correctAnswer": 1
},
{
"question": "¿Cuántos Pokémon hay en total hasta la séptima generación, incluyendo formas alternativas?",
"option": ["a) 721", "b) 802", "c) 893"],
"correctAnswer": 1
},
{
"question": "¿Cuál es el Pokémon conocido por cambiar de forma según el clima y la hora del día?",
"option": ["a) Castform", "b) Shaymin", "c) Mimikyu"],
"correctAnswer": 0
},
{
"question": "¿Qué Pokémon tiene la habilidad 'Presión' y es conocido por ser el guardián de la Torre Hojalata?",
"option": ["a) Lugia", "b) Ho-Oh", "c) Suicune"],
"correctAnswer": 2
}
]
]
75 changes: 39 additions & 36 deletions js/sript.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ function displaySavedQuestion() {
const savedQuestionString = localStorage.getItem('Savedquestions');
const savedQuestion = JSON.parse(savedQuestionString);
const savedScore = JSON.parse(localStorage.getItem('savedScore'));

if (savedQuestion != null && savedQuestion.length > 0 ) {
questions = savedQuestion;
score = savedScore;
Expand All @@ -71,59 +72,61 @@ function displaySavedQuestion() {
};

// funcion pa mostrar las preguntas
function displayCurrentQuestion() {
if (questions.length > 0) {
currentQuestionIndex = (Math.floor(Math.random() * (1 + questions.length - 1)));
const currentQuestion = questions[currentQuestionIndex];
startTimer();
questionHtmlElement.innerHTML = '';
for (let i = 0; i < currentQuestion.question.length; i++) {
const span = document.createElement('span');
span.setAttribute('class', 'fall letras');
span.setAttribute('style', `animation-delay: ${i / 20}s`);
span.textContent = currentQuestion.question[i];
questionHtmlElement.appendChild(span);
console.log(currentQuestion.question);
}

optionAButton.removeEventListener('click', handleOptionAClick);
optionBButton.removeEventListener('click', handleOptionBClick);
optionCButton.removeEventListener('click', handleOptionCClick);


optionAButton.textContent = currentQuestion.option[0];
optionBButton.textContent = currentQuestion.option[1];
optionCButton.textContent = currentQuestion.option[2];
colorButons();

// Agregar eventos click para los botones de opción
optionAButton.addEventListener('click',handleOptionAClick);

optionBButton.addEventListener('click',handleOptionBClick);

optionCButton.addEventListener('click',handleOptionCClick);
function displayCurrentQuestion() {
if (questions.length > 0) {
currentQuestionIndex = Math.floor(Math.random() * questions.length);
const currentQuestion = questions[currentQuestionIndex];

// Verifica si currentQuestion es un objeto válido y tiene las propiedades necesarias
if (currentQuestion && currentQuestion.hasOwnProperty('question') && currentQuestion.hasOwnProperty('option') && currentQuestion.hasOwnProperty('correctAnswer')) {
startTimer();
questionHtmlElement.innerHTML = '';
for (let i = 0; i < currentQuestion.question.length; i++) {
const span = document.createElement('span');
span.setAttribute('class', 'fall letras');
span.setAttribute('style', `animation-delay: ${i / 20}s`);
span.textContent = currentQuestion.question[i];
questionHtmlElement.appendChild(span);
console.log(currentQuestion.question);
}

optionAButton.removeEventListener('click', handleOptionAClick);
optionBButton.removeEventListener('click', handleOptionBClick);
optionCButton.removeEventListener('click', handleOptionCClick);

optionAButton.textContent = currentQuestion.option[0];
optionBButton.textContent = currentQuestion.option[1];
optionCButton.textContent = currentQuestion.option[2];
colorButons();

// Agregar eventos click para los botones de opción
optionAButton.addEventListener('click', handleOptionAClick);
optionBButton.addEventListener('click', handleOptionBClick);
optionCButton.addEventListener('click', handleOptionCClick);
} else {
// Si currentQuestion no tiene el formato esperado, mostrar un mensaje de error o realizar alguna acción de manejo.
console.error('Formato de pregunta no válido:', currentQuestion);
}
} else {
clearInterval(countdownTimer);
timer.remove();
questionHtmlElement.textContent = `Juego terminado ${score > 0 ? 'tu puntaje es : ' + score : 'Perdiste Bobo'}`;
questionHtmlElement.textContent = `Juego terminado ${score > 0 ? 'tu puntaje es : ' + score : 'Perdiste Bobo'}`;
optionAButton.style.display = 'none';
optionBButton.style.display = 'none';
optionCButton.style.display = 'none';

const resetButton = document.createElement('button');
resetButton.setAttribute('id', 'resetButton');
resetButton.textContent = ('Reniciar Juego')
resetButton.textContent = ('Reniciar Juego');
buttonDiv.append(resetButton);

resetButton.addEventListener('click',() => {
resetButton.addEventListener('click', () => {
score = 0;
localStorage.clear();
window.location.reload();

});
}
};
}

// Función para iniciar el temporizador
function startTimer() {
Expand Down

0 comments on commit 0e64f4e

Please sign in to comment.