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

Daniel Salvatori
Daniel Salvatori
2,658 Points

Critique my solution for part 1 please.

Hi team,

here is my solution below, let me know what I can improve.

As is it works, although i would like my print() to print on 2 separate lines and i don't know how to do that. Just formatting.

Also, I first made it a function, but commented that part out and it works just the same. Should I just get rid of the function all together?

var quizQuestions = [
 ['Who was the first woman in space?', 'valentina tereshkova'], 
 ['In what year did the Korean War begin?', '1950'],
 ['Who was the first US President to die in office?', 'william henry harrison'] 
  ]

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

var correctAnswer = 0
var wrongAnswer = 0

/*function askQuestion(question){*/
for (var i = 0; i <3; i+=1){
 var answer = prompt(quizQuestions[i][0]); 
 if (answer.toLowerCase() === quizQuestions[i][1]){
  correctAnswer += 1} else {
    wrongAnswer += 1}
}
  print('You got '+ correctAnswer + ' questions correct!');
  print('You got ' + wrongAnswer + ' questions wrong :(');
//}


//askQuestion();

Thanks

Joseph Chiang
Joseph Chiang
3,942 Points

I think the code is generally good, and yes, the function you commented out is not needed, but for the formatting (2 lines) you were talking about try to call the print function like this:

print('<p>You got '+ correctAnswer + ' questions correct!</p>');
print('<p>You got ' + wrongAnswer + ' questions wrong :(</p>');

Including the html helps with the formatting because css is already attached to some html elements, so you can replace <p> with <h1> or <h2> as well depending on your desired sizing/formatting. Cheers!

Daniel Salvatori
Daniel Salvatori
2,658 Points

Thanks for the feedback, i figured the formatting out soon after