Soy nuevo (como hace 4 días estaba buscando en Google cómo iniciar un archivo HTML) en la codificación y necesito ayuda para descubrir cómo separar las respuestas de mi cuestionario en líneas separadas. ¿Alguien puede ayudarme? Traté de encontrar una manera de usar saltos de línea, pero como soy nuevo, he tenido problemas para encontrar una manera de hacerlo que no afecte el resto del código. Solo incluí la parte con la que necesito ayuda. Si alguien necesita una versión más completa, por favor hágamelo saber.
Aquí está mi código:
var myQuestions = [{ question: "", answers: { A: 'Emily should tell the other members what role she is now going to fulfill.', B: 'Emily cannot do anything until her eight-year term is up.', C: 'Emily needs to talk to the other members about a role swap.' }, correctAnswer: 'c' }, ]; var quizContainer = document.getElementById('quiz'); var resultsContainer = document.getElementById('results'); var submitButton = document.getElementById('submit'); generateQuiz(myQuestions, quizContainer, resultsContainer, submitButton); function generateQuiz(questions, quizContainer, resultsContainer, submitButton) { function showQuestions(questions, quizContainer) { var output = []; var answers; for (var i = 0; i < questions.length; i++) { answers = []; for (letter in questions[i].answers) { answers.push( '<label>' + '<input type="radio" name="question' + i + '" value="' + letter + '">' + letter + ': ' + questions[i].answers[letter] + '</label>' ); } output.push( '<div class="question">' + questions[i].question + '</div>' + '<div class="answers">' + answers.join('') + '</div>' ); } quizContainer.innerHTML = output.join(''); } function showResults(questions, quizContainer, resultsContainer) { var answerContainers = quizContainer.querySelectorAll('.answers'); var userAnswer = ''; var numCorrect = 0; for (var i = 0; i < questions.length; i++) { userAnswer = (answerContainers[i].querySelector('input[name=question' + i + ']:checked') || {}).value; if (userAnswer === questions[i].correctAnswer) { numCorrect++; answerContainers[i].style.color = 'darkgreen'; } else { answerContainers[i].style.color = 'darkred'; } } resultsContainer.innerHTML = numCorrect + ' out of ' + questions.length; } showQuestions(questions, quizContainer); submitButton.onclick = function() { showResults(questions, quizContainer, resultsContainer); } }
simplemente puede usar los elementos de la lista para una línea separada de preguntas como esta, consulte la documentación y aplique el estilo css en consecuencia. https://www.w3schools.com/html/html_lists.asp
<ul> <li>Ans1<li> <li>Ans2<li> <li>Ans3<li> </ul>
Simplemente ponga cada respuesta en un div
; en su código use '<div><label>'
y '</label></div>'
.