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 trialDoron Geyer
Full Stack JavaScript Techdegree Student 13,897 Pointscant figure out how to make ordered list from array data.
I have tried creating a function to build an ordered list to print out my code, however it doesnt seem to work. I am not sure how to do this. My code gives all the data I need for the challenge but my output onto the webpage needs to display the 2 arrays as ordered lists and I just cant get it to work, with what ive tried it gives undefined.
I have commented out the code that I was trying to write for this purpose , the last 2 lines were 2 variations I tried both return undefined.
2 Answers
Chapman Cheng
PHP Development Techdegree Graduate 46,936 PointsHey Doron, on this line
for(i<0;i<list.length;i++){
// it should be
for (let i = 0 ; i < list.length ; i ++) {
I think you have a typo of <
but should be =
Doron Geyer
Full Stack JavaScript Techdegree Student 13,897 PointsThanks, you are correct I have changed it ! good spot , sadly however it doesnt fix my overall issue.
went looking through my typos, and I made my variable in the function different.
listHTML
and listHtml
thanks to chapman for reminding me to lookout for typos and to take a break
Doron Geyer
Full Stack JavaScript Techdegree Student 13,897 Pointshere is the final corrected code:
var incorrectQ = [];
var correctQ = [];
var corAns = 0;
var questions=[
["which programming lanugage are we using?", "JavaScript"],
["which programming language is named after a snake?", "Python"],
["which programming language is named after a gemstone", "Ruby"]
]
function print(message) {
document.write(message);
}
function buildHtmlList(list){
var listHTML= "<ol>" ;
for(i=0;i<list.length;i++){
listHTML+= "<li>" + list[i] + "</li>";
}
listHTML+= "</ol>";
print(listHTML);
}
for(i=0;i<questions.length;i+=1){
var ques = prompt(questions[i][0]);
if(ques.toLowerCase() === (questions[i][1]).toLowerCase()){
correctQ.push(questions[i][0]);
corAns++
}else if(ques.toLowerCase() !== (questions[i][1]).toLowerCase()){
incorrectQ.push(questions[i][0]);
}
}
print(`you got ${corAns} questions correct and ${questions.length - corAns} incorrect.`);
print("<h1>you got the following questions correct</h1>");
buildHtmlList(correctQ);
print("<h1>you got the following questions incorrect</h1>");
buildHtmlList(incorrectQ);
Doron Geyer
Full Stack JavaScript Techdegree Student 13,897 PointsDoron Geyer
Full Stack JavaScript Techdegree Student 13,897 Pointssnapshot for actual code: https://w.trhou.se/7ndu589ano