Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

294
Vistas
how to assign points to each option in a question javascript

I just want to assign a value for each option in the list then i can calculate the score based on the score of each question.

So I saw today an example of a html quiz app and I want to do like it but the idea is each choice has a certain score which is calculated at the end of the questions but the once I saw online was just counting the correct questions till the end of the array. Mine is assigning a certain mark for each choice that means there's no 'one correct answer' but rather multiple correct answers with different degrees of correctness. The problem is I can't assign each answer to a grade i tried it with objects but I couldn't access it.

const Data = [
  {
    question: "What does   HTML stands for ?",
    
    a: "Hyper Text Markup Language ",
    b: "Hypo Text Markup Language",
    c: "Hard Test Marking Language",
    d: "High Text Marking Language",
    answer: {a:2, b:3, c:5, d:4},
  }
];

function nextQuestion() {
  const answer = getValue();
  if (answer) {
    if (answer === Data[initialQuize].answer[key]) {
      score=score+ Data[initialQuize].answer[value];
    }
    initialQuiz++;
    if (initialQuize < Data.length) {
      loadQuiz();
    } else if (score === Data.length) {
      quiz.innerHTML = `<h1> Congratulations<br/>You scored ${score}/${Data.length}</h1>`;
    } else {
      quiz.innerHTML = `<h1> You scored ${score}/${Data.length}`;
    }
  }
}

I hope I made it clear. Thanks

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

I'd say that answers should be an array of objects with text and points properties. I would structure it like this:

function nextQuestion() {
  const answer = getValue();

  if (answer && answer === Data[initialQuize].answers[key].text) {
    score = score + Data[initialQuize].answers[key].points;
  }
    
  // ...
}

const Data = [{
    question: "What does HTML stand for?",
    answers: [{
        text: "Hyper Text Markup Language ",
        points: 2
      },
      {
        text: "Hypo Text Markup Language",
        points: 3
      },
      {
        text: "Hard Test Marking Language",
        points: 5
      },
      {
        text: "High Text Marking Language",
        points: 4
      }
    ]
  },
  {
    question: "What does XML stand for?",
    answers: [{
        text: "Xylophone Markup Language ",
        value: 2
      },
      {
        text: "X-ray Markup Language",
        value: 3
      },
      {
        text: "Extensible Markup Language",
        value: 5
      },
      {
        text: "Xavier's Morphine Language",
        value: 4
      }
    ]
  }
];
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda