Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript JavaScript Basics (Retired) Making Decisions with Conditional Statements The Conditional Challenge Solution

Daphne Tideman
Daphne Tideman
9,006 Points

When I try to run the JavaScript nothing happens, not sure what the issue is?

The following shows my code:

// quiz begins, no answers correct var correct = 0;

//ask questions var answer1 = prompt("Name a programming language that's also a gem"); if (answer1.toUpperCase() === 'RUBY'){ correct += 1; } var answer2 = prompt("Name a programming language that's also a snake"); if (answer2.toUpperCase === 'PYTHON') { correct += 1; } var answer3 = prompt("What language do you use to style web pages?"); if (answer3.toUpperCase === 'CSS') { correct += 1;

var answer4 = prompt("What language do you use to build the structure of web pages?"); if (answer4.toUpperCase === 'HTML') { correct += 1; } var answer5 = prompt("What language do you use to add interactivity to a web pages?"); if(answer5.toUpperCase === 'JAVASCRIPT') { correct += 1; }

// output results document.write("<p> You got "+ correct + " out of 5 questions correct.<p.");

//output rank if (correct === 5) { document.write("<p><strong>You earned a gold crown!</strong></p>"); } else if ( correct>= 3) { document.write("<p><strong>You earned a silver crown.</strong></p>"); } else if ( correct>= 1) { document.write("<p><strong>You earned a bronze crown.</strong></p>"); } else { document.write("<p><strong>No Crown</strong></p>"); }

1 Answer

  1. you have commented few codelines : line 1, 3, 13, 15.
  2. at line 13 you forgot to add a quote mark ".
  3. at line 6 you forgot to close the if command by } curly braces
  4. except that everything was perfect!
// quiz begins, no answers correct 
var correct = 0;


var answer1 = prompt("Name a programming language that's also a gem");
if (answer1.toUpperCase() === 'RUBY'){
  correct += 1; 
} 
var answer2 = prompt("Name a programming language that's also a snake");
if (answer2.toUpperCase === 'PYTHON') {
  correct += 1; 
}
var answer3 = prompt("What language do you use to style web pages?"); 
if (answer3.toUpperCase === 'CSS') {
  correct += 1;}

var answer4 = prompt("What language do you use to build the structure of web pages?"); 
  if (answer4.toUpperCase === 'HTML') {
    correct += 1;
  }
  var answer5 = prompt("What language do you use to add interactivity to a web pages?"); if(answer5.toUpperCase === 'JAVASCRIPT')
  { correct += 1; }

// output results 
document.write(" You got "+ correct + " out of 5 questions correct.");

//output rank 
if (correct === 5) 
{ document.write("You earned a gold crown!"); } 
else if ( correct>= 3)
{ 
document.write("You earned a silver crown."); 
} 
else if ( correct>= 1) { 
document.write("You earned a bronze crown.");
} 
else {
  document.write("No Crown"); 
}```