Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialNicolás Melgarejo
14,390 PointsMy solution
function createListItems(arr) { // el argumento en un array
let items =''; // aqu'i concatenaremos los items
for (let i=0; i < arr.length; i++ ){ // comenzamos a recorrer el array desde 0 haata arr.length
items += `<li>${arr[i]}</li>` // cada elemento lo concatenamos en un li.
}
return items;
}
const quizQuestions = [
['raiz cuadrada de 4?', '2'],
['10 - 0,1 =', '0,9'],
['antecesor de 2', '1']
];
let score = 0;
let rightQuestions = [];
let wrongQuestions = [];
for (i = 0; i < quizQuestions.length ; i++) {
let question = quizQuestions[i][0];
let answer = quizQuestions[i][1]
let response = prompt(question);
if (response.toLowerCase() === answer) {
rightQuestions.push(question);
score++;
} else {
wrongQuestions.push(question);
}
}
const message = `Obtuviste ${score} respuestas correctas`;
document.querySelector('main').innerHTML = `<h1>${message}</h1> <h2>You got this questions right:</h2> <ol>${createListItems(rightQuestions)}</ol>
<h2>You got this questions wrong:</h2> <ol>${createListItems(wrongQuestions)}</ol>`