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 JavaScript Basics (Retired) Making Decisions with Conditional Statements The Conditional Challenge

Dee K
Dee K
17,815 Points

Feedback on the Conditional Challenge.

alert('This is the history trivia quiz. Guess the answers to 5 questions and you will get a ranking. Good Luck!');

var score = 0;

var first_question = prompt("What year did the Titanic sink?");
  if ( parseInt(first_question) === 1912 ) {
      score += 1;
  }

var second_question = prompt("In what year did World War II begin?");
  if ( parseInt(second_question) === 1939 ) {
      score += 1;
  } 

var third_question = prompt("Which U.S president signed the Federal Reserve Act?");
  if ( third_question.toUpperCase() === 'WOODROW WILSON' || third_question.toUpperCase() === 'WILSON' ) {
      score += 1;
  }

var fourth_question = prompt("Who created the first steam engine?");
  if ( fourth_question.toUpperCase() === 'JAMES WATT' ) {
      score += 1;
  }

var fifth_question = prompt("Who created the largest empire in human history?");
  if ( fifth_question.toUpperCase() === 'GENGHIS KHAN' ) {
      score += 1;
  } 

alert('You got ' + score + ' out of 5 correct.' + ' Press OK to see your ranking.');

if ( score == 5 ) {
    document.write('<p> You get a ranking of a Gold Crown! This places you in the highest ranking of all quiz takers! Good job!</p>');
} else if ( score == 3 || score == 4 ) {
    document.write('<p> You get a ranking of a Silver Crown! This places you in the second highest ranking of all quiz takers! Nice effort!</p>');
} else if ( score == 2 || score == 1 ) {
    document.write('<p> You get a ranking of a Bronze Crown! This places you in the third ranking of all quiz takers! You have a decent knowledge of history.</p>');
} else {
    document.write('<p> You get no ranking and no crown. You got every question wrong. Time to brush up on your history knowledge.</p>');
}  

This code works fine but it feels very amateurish and I would like an experienced programmer's feedback.

Any suggestions or advice to improve this code would be greatly appreciated!

Cheers!

David Bath
David Bath
25,940 Points

Considering where you are in the JavaScript track, I'd say this is pretty good! Once you learn about arrays and functions you will find lots of ways to improve this, but right now you are using the tools that Dave taught you. Good job!

Andy Heavens
seal-mask
.a{fill-rule:evenodd;}techdegree
Andy Heavens
Full Stack JavaScript Techdegree Student 2,960 Points

I have just completed the functions, loops and arrays etc and you will soon see that there are ways to improve, shorten, and tidy up your code. All part of the learning process, one step at a time. Your code at this point looks better than mine did at the same point! :-)

1 Answer

Dee K
Dee K
17,815 Points

thanks for the feedback guys!