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 trial

JavaScript JavaScript Loops, Arrays and Objects Tracking Multiple Items with Arrays Build a Quiz Challenge, Part 1

Feedback my code - thank you..

//printfunction

function print(message) {
  document.write(message);
}

//Store values

var correctAnswered = [];
var wrongAnswered = [];

//Questions

var question =[
                ["What is the capital of Sweden?", "stockholm"],
                ["What is the capital of Norway?", "oslo"],
                ["What is the capital of Finland?", "helsinki"]
              ];


//function for printing Question and looping question

function printQ(question){
for(i=0; i<question.length; i+=1){

var userAnswer = prompt(question[i][0]);
var rightAnswer = question[i][1];

//conditional statement and pushing values to variables for storing  

if(userAnswer.toLowerCase()===rightAnswer){
correctAnswered.push("<li> " + question[i][0] +"<br>" + "The right answer is "+ rightAnswer + "</li>");
}
  else{
 wrongAnswered.push("<li> " + question[i][0] + "<br>" + "The right answer is "+ rightAnswer + "</li>");

  }
}
//Print to dom

print("<h1>" + "You answered " + correctAnswered.length  + " questions right!" + "</h1>");
print("<h2> Here is your correct list</h2>"  + "<ol>" + correctAnswered + "</ol>");  
print("<h2> Here is your wrong list</h2>" +  "<ol>" + wrongAnswered + "</ol>");

}

printQ(question);

I get a comma after each row not sure why, annoying.

Konrad Pilch
Konrad Pilch
2,435 Points

Did you create this on your own? With little help from the videos? If no one reply i will look at it when i wake up, now im too tired, i just checked forum to see whats happening.

But im leanring JS too and i like this code.

2 Answers

Yes, I did it on my own with help of course materials. I'm w8ing for tomorrow to see the teachers solution =) and thank you :)

Konrad Pilch
Konrad Pilch
2,435 Points

I don't know :D im a beginner too, but from my point is clean and nicely done. Im going to learn from this deffinitelly :D

Something i found beeing useful to learn JS OOP if ur interested is this

Well, its just a start to it, but with combination on treehouse ud gonna learn a lot.

Thats cool. Yeah, I'm planning to finnish front-end and then going fullstack JS.