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 trialJoshua Moten
2,403 PointsAccidently Made an Ordered List without <ol>
// 1. Create a multidimensional array to hold quiz questions and answers
const quiz = [
['Who am I...I beat 1,000 Philistine soilders with a jawbone of an ass: ', 'samson'],
['What am I...I was crush into powder by Moses and the people drank me: ', 'golden calf'],
['What am I...I was taken out of a lions carcuse and was given to be ate: ', 'honey']
];
// 2. Store the number of questions answered correctly
let correctAnswers = 0;
let correctAnswerList = [];
let wrongAnswerList = [];
/*
3. Use a loop to cycle through each question
- Present each question to the user
- Compare the user's response to answer in the array
- If the response matches the answer, the number of correctly
answered questions increments by 1
*/
for (let i=0; i<quiz.length; i++) {
let questions = prompt(`${quiz[i][0]}`);
if (questions.toLowerCase() === quiz[i][1]) {
correctAnswerList.push(quiz[i][0])
correctAnswers++
} else {
wrongAnswerList.push(quiz[i][0])
}
}
function createListItems(arr) {
let items = '';
for (let i = 0; i < arr.length; i++) {
items += `<li>#${arr[i].indexOf(arr[i][i])+1} ${arr[i]}</li>`;
}
return items;
}
// 4. Display the number of correct answers to the user
document.querySelector('main').innerHTML = `<p>You got <strong>${correctAnswers} of ${quiz.length}</strong> correct!</p><br>
<strong><p>You got these questions correct:</p></strong><br><br>
<p>${createListItems(correctAnswerList)}<p>
<strong>You got these questions wrong:</strong>
<p>${createListItems(wrongAnswerList)}</p>`;
I forgot the <ol> for my <li> tags but it still works lol
2 Answers
Steven Parker
231,248 PointsIt might work, but it's not proper HTML. How this is displayed is up to the browser and you can't rely on what the browser might do with it. I tried it in Chrome and it did display, but as a <ul>
instead of an <ol>
.
Also, in a properly formed <ol>
you would not need to display the index number yourself as the list would do that for you.
Joshua Moten
2,403 PointsYeah I definitely overthought the process which is one of my biggest flaws