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 trialMichael Arasimowicz
Full Stack JavaScript Techdegree Student 1,794 PointsSolution but not happy with it
It gets the job done but seeing the video on how the instructor did it vs how I did it, makes me feel like I am not understanding and therefore not able to use methods that we learned about. Having real trouble keeping the possibilities in arms reach.
const qATest = [
['What color is the moon?', 'white'],
['When was Einstein born?', '1879'],
['What is the name of the crypto sock business?', 'sockhodler'],
['Will we ever become a true programmer?', 'yes']
];
// 2. Store the number of questions answered correctly
let answerCorrect = 0;
let right = '';
let wrong = '';
for ( let i = 0; i < qATest.length; i++ ){
const questions = prompt(qATest[i][0]);
if (questions.toLowerCase() === qATest[i][1]) {
answerCorrect++;
right += `<li>${qATest[i][0]}</li>`;
}else if (questions.toLowerCase() != qATest[i][1]){
wrong += `<li>${qATest[i][0]}</li>`;
}
}
document.querySelector('main').innerHTML = `
<h1>You got ${answerCorrect} question(s) correct</h1>
<h2> You got these questions right:</h2>
<ol>
${right}
</ol>
<h2> You got these questions wrong:</h2>
<ol>
${wrong}
</ol>
`;
1 Answer
Steven Parker
231,269 PointsI think you're judging yourself too harshly. Remember that "gets the job done" is the primary indicator of success in programming. Also bear in mind that there is rarely just one "right way" to approach any problem.
The instructor's use of arrays and functions makes the code a bit more compact and modular, but your code still meets every stated objective. Employing the other concepts will come with practice and/or more explicit directions.
For this challenge I'd say, job well done!