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

Daniel Salvatori
2,658 PointsCan I have some feedback on my code?
So the program works, but looking at others' solutions mine seems very basic/not sophisticated , anything I should change in my code?
var questionOne = prompt('What year did the Edmonton Oilers first win the Stanley Cup?');
var questionTwo = prompt('Who held the single season scoring record before Gretzky set the new record?');
var questionThree = prompt('Which Toronto Maple Leafs player scored 10 points in one game in 1976?');
var questionFour = prompt('Who holds the record for most points scored by a player in his rookie season?');
var questionFive = prompt('Which goaltender was voted the most outstanding player in the league by his fellow players in 1981?');
var correct = 0
if(questionOne === '1984'){
correct +=1
}
if(questionTwo.toUpperCase() === 'ESPOSITO' || questionTwo.toUpperCase() ==='PHIL ESPOSITO'){
correct +=1
}
if(questionThree.toUpperCase() === 'SITTLER' || questionThree.toUpperCase() ==='DARRYL SITTLER'){
correct +=1
}
if(questionFour.toUpperCase() === 'SELANNE' || questionFour.toUpperCase() === 'TEEMU SELANNE'){
correct +=1
}
if(questionFive.toUpperCase() === 'LIUT' || questionFive.toUpperCase() ==='MIKE LIUT'){
correct +=1
}
console.log(correct)
if(correct === 5){
document.write(' You answered all 5 correctly, gold crown!');
}else if( correct === 4){
document.write(' You answered 4 out of 5 correctly, silver crown!');
} else if(correct === 3){
document.write('You answered 3 out of 5 correctly, silver crown!');
} else if(correct === 2){
document.write('You answered just 2 out of 5 correctly, you get a bronze crown.');
} else if(correct === 1){
document.write('You answered only 1 out of 5 correclty, you get a bronze crown.');
} else if(correct === 0){
document.write('You answered 0 questions correctly, you scrub. Go home and take a shower, wash the shame off of you.');
}
1 Answer

Nick Trabue
Courses Plus Student 12,666 PointsThere's likely always going to be a more sophisticated and DRY way. As you continue to practice and learn new things you'll come back to something you did a long time ago and think of a better solution. If you catch yourself repeating multiple lines of code, it may be a good idea to think of another way to do things. For example, in your if block there
if(correct === 5){
document.write(' You answered all 5 correctly, gold crown!');
}else if( correct === 4){
document.write(' You answered 4 out of 5 correctly, silver crown!');
} else if(correct === 3){
document.write('You answered 3 out of 5 correctly, silver crown!');
} else if(correct === 2){
document.write('You answered just 2 out of 5 correctly, you get a bronze crown.');
} else if(correct === 1){
document.write('You answered only 1 out of 5 correclty, you get a bronze crown.');
} else if(correct === 0){
document.write('You answered 0 questions correctly, you scrub. Go home and take a shower, wash the shame off of you.');
}
can be shortened to something like this
var taunt = "gold crown!" ;
if (correct === 0) {
taunt = "you scrub. Go home and take a shower, wash the shame off of you."
} else if (correct >= 2) {
taunt = "you get a bronze crown"
} else if (correct >= 4 && correct <5){
taunt = "silver crown!"
}
var message = document.write("You answered " + count + " out of 5 correctly, " + taunt);
Just an example. There are even more advanced ways than that. There is no "correct" way in an example like this but you should strive to repeat code as little as you can within the realm of your comfortability.