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 trialguram dgebuadze
Front End Web Development Techdegree Student 4,122 PointsIs my code right to do the same in the future?
var question;
var answer;
var response;
var correct = 'This is the question(s) you got right' + '<ol>';
var wrong = 'This is the question(s) you got wrong' + '<ol>';
function print(message) {
document.write(message);
}
var questions = [
['When did the \'First world War\' begin? ', 1914],
['When did the \'Second World War\' begin? ', 1939],
['When did the \'Oqtomber Revolution\' happened in Russia? ', 1917]
];
for (var i = 0; i < questions.length; i++) {
question = questions[i][0];
answer = questions[i][1];
response = parseInt(prompt(question));
if ( response === answer ) {
correct += '<li>' + question + '</li>';
} else {
wrong += '<li>' + question + '</li>';
}
}
correct += '</ol> ';
wrong += '</ol>';
print(correct + wrong);
3 Answers
Steven Parker
231,248 PointsYou'll find that the more complex the program, the more ways there will be to write the code to do it. And 90% of "right" is achieving the intended results. The rest is making the code efficient, concise, and easily read and maintained. This code seems to do well in all those criteria, so if it also performs just like the example code, I'd say it's "right" for sure.
Good job!
guram dgebuadze
Front End Web Development Techdegree Student 4,122 PointsHah no, not yet :D
Steven Parker
231,248 PointsWell, good. But can you elaborate a bit on the question?
guram dgebuadze
Front End Web Development Techdegree Student 4,122 PointsIn the video teacher did this code little bit differently and I am interested is this ok to wright this way?
Steven Parker
231,248 PointsSteven Parker
231,248 PointsWhat kind of "future" requirements are you concerned about? I hope not a third world war!