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 trialstef22
5,354 PointsWhat do u think of my code, please feedback
Thanks for looking at my code :D
//Questions var q1 = prompt('Is JavaScript a programming langue?'); var q2 = prompt('Is Unity a programming langue?'); var q3 = prompt('Is C# a programming langue?'); var q4 = prompt('Is TreeHouse a programming langue?'); var q5 = prompt('Is Boolean a programming langue?');
var score = 0;
//Check if qustions are true or false.
if(q1 === "yes") {
score += 1;
} else {
score = score;
}
if(q2 === "no") {
score += 1;
} else {
score = score;
}
if(q3 === "yes") {
score += 1;
} else {
score = score;
}
if(q4 === "no") {
score += 1;
} else {
score = score;
}
if(q5 === "no") {
score += 1;
} else {
score = score;
}
//Check what the score is and give a plate if(score >= 4) { document.write('Good job! U earnd a gold plate'); } else if(score >= 2) { document.write('Good job! U earnd a silver plate'); } else if(score >= 1){ document.write('Good job! U earnd a bronze plate'); } else { document.write('Please try again!'); }
document.write('<p>Total score: ' + score + '</p>');
1 Answer
Gabriel D. Celery
13,810 PointsThe "if" statement works on its own. Meaning instead of this:
if (q1 === "yes"){ score += 1; } else { score = score;}
if(q2 === "no") { score += 1; } else { score = score;}
if(q3 === "yes") { score += 1; } else { score = score;}
if(q4 === "no") { score += 1; } else { score = score;}
if(q5 === "no") { score += 1; } else { score = score;}
You can write this
if (q1 === "yes"){ score += 1; }
if(q2 === "no") { score += 1; }
if(q3 === "yes") { score += 1; }
if(q4 === "no") { score += 1; }
if(q5 === "no") { score += 1; }
Especially since the else statements don't add anything meaningful to the code.
stef22
5,354 Pointsstef22
5,354 PointsThanks