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

Jesse Fister
Jesse Fister
11,968 Points

Unexpected end of input

The results say 'Syntax error: Unexpected end of input' However, the code is identical to Dave's.

// 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 page?"); 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 for you, loser.</strong><p>"); }

Clayton Perszyk
Clayton Perszyk
Treehouse Moderator 48,850 Points

Hey Jesse

Try addin () to all of your calls to toUpperCase().

Example:

answer.toUpperCase();

To invoke a function/method you have to add parentheses.

1 Answer

Clayton Perszyk
MOD
Clayton Perszyk
Treehouse Moderator 48,850 Points

Here's your 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 page?"); 

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 for you, loser."); 
    }

Here is your code after debugging (I didn't do a thorough testing, but I was able to finish the game by passing each question condition; I didn't test all of the output rank conditions, so you might test those.):

// 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 page?"); 

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 for you, loser."); 
    }