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

scott Walker
scott Walker
2,506 Points

im doing something wrong with my conditionals as console keeps giving me syntax errors

Uncaught SyntaxError: Unexpected token var is the error im receiving just now on all the else clauses

// set up th questions countdown and score// 
  var questionsLeft ;
  var questions = 5 ;
  var score = 5 ; 

  //variables for quiz answers//

  var quizOne  =   FINLAND ;
  var quizTwp  =   RED     ;
  var quizThree=   MISTLETOE;
  var quizFour =   SCROOGE ;
  var quizFive =   MINCE  ;

  // variables for rankings//
  var rank   ;
  var gold   ;
  var silver ;
  var bronze ;

  if (var score = 5 || 4 ){
  rank = gold }
  else if (score = 3 ||2){
  rank = silver }
  else if (score = 1||0) {
    rank = bronze }




  // ask 5 questions //
  /* 1- In what country does santa live?
  2- what colour is rudolphs nose 
  3- what plant do you kiss under
  4- who was the old grumpy man in a christmas carol 
  5- what kind of pie do you give santa
  */

  //question 1 //

  alert('welcome to our xmas quiz!');
  alert(questionsLeft)
  var quizOne = prompt('in What country does santa live?');
  quizOne = toUppercase(quizOne);
  quizOne = (true)              ;
  else { (score = (score - 1) )   ;
          } ;

  // question 2 //
   var questionsLeft = (questions - 1 )
   var quizTwo = prompt('what colour is rudolphs nose?');
   quizTwo = toUppercase(quizTwo);
   quizTwo = (true);
   else { (score = (score - 1) ) }

  // question 3 //
  var questionsLeft = (questions - 1 )
  var quizThree = prompt('what plant do you kiss under?');
  quizThree = toUppercase(quizThree);
  quizThree = (true) ;
  else { (score = (score - 1) )}


   //question 4 //
   var questionsLeft = (questions - 1 )
   var quizFour = prompt('who was the old grumpy man in a christmas carol?');
   quizFour = toUppercase(quizFour)
   quizFour = (true) ;
   else { (score = (score - 1) )}

   //question 5 //
   var questionsLeft = (questions - 1 )
   var quizFive = prompt('what kind of pie do you give santa?');
   quizFive = toUppercase(quizFive)
   quizFive = (true) ;
   else { (score = (score - 1) ) }

    /*rank the player for there score 
    5 - 4 = gold
    3 - 2 = silver
    1 - 0 = bronze
    */

   document.write('your rank is  ' + rank )

Moderator edited: Markdown added so that code renders properly in the forums

2 Answers

Doron Geyer
seal-mask
.a{fill-rule:evenodd;}techdegree
Doron Geyer
Full Stack JavaScript Techdegree Student 13,897 Points

if I look the first thing I notice is this

 quizOne = toUppercase(quizOne); quizOne = (true) ; else { (score = (score - 1) ) ; } ;`

you have put quizOne in brackets, there shouldnt be anything in those brackets .

you would want your code to look more like this:

quizOne=quizOne.toUpperCase(); `

the c in your toUpperCase is lower case so it wont call the function. and the () at the end of the toUpperCase shows that you are calling the method. also you have

quizOne=(true); 

you dont need to put boolean values in ()

quizOne= true; 

will work fine.

also remember that your program runs things in the order that it reads them , so make sure that your code is executing in the correct order .

Your || or OR operator also has the wrong syntax. you need to have a complete statement on either side of the || operator.

so

if (var score = 5 || 4 )` wont work
you need to have it as `if (var score = 5 || var score =4 )`

also remember that you are using = that is for assignment , you want to be using == or === .

if you correct these things then I'll see if I can help you further and explain/troubleshoot with you as you go. I have given you my code for the same question, it may be easier for you to compare how different things are used.

document.write("<h1> Welcome to the quiz, it consists of five questions about programming. Can you answer them all? </h1><br>");
var rank;
var feedback;
var answerCount = 0;
var studentAnswer= false;
var answer = prompt("which programming language is named after an animal?")
if(answer.toLowerCase()=== "python"){
answerCount++;
}
answer=prompt("which programming language uses a coffee cup as a logo?")
if(answer.toLowerCase()=== "java"){
answerCount++;
}
answer=prompt("which programming language is named after a gemstone?")
if(answer.toLowerCase()=== "ruby"){
answerCount++;
}
answer=prompt("is JavaScript a case sensitive language 'yes' or 'no';?")
if(answer.toLowerCase()=== "yes"){
answerCount++;
}
answer=prompt("did you enjoy this quiz? 'yes' or 'no' there is no correct or incorrect answer")
if(answer.toLowerCase()=== "yes" || answer.toLowerCase()==="no"){
answerCount++;
  if(answer.toLowerCase()=== "yes"){
     studentAnswer=true;
     }else{
   feedback= prompt("please write what you think we could improve on our next quiz, we value your opinion!");   
}
}
//score rank system
if(answerCount===1||answerCount===2){
rank= "bronze";
}else if(answerCount===3||answerCount===4){
rank= "Silver";
}else{
rank= "GOLD!!!!";
}
document.write("Thanks for attempting our quiz! you got " + answerCount + " questions correct out of 5 your new rank is " + rank);
Jennifer Nordell
seal-mask
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there, Doron Geyer! I took the liberty of changing your "comment" to an answer as it is more appropriate as an answer. Thanks for helping out in the Community :sparkles:

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there, scott Walker! I can see that you're trying really hard. Here are some things that I notice.

In the beginning, you have created a few variables which I believe are meant to be the answers. But the thing on the right side is not a string, which will later cause problems. For instance:

Where you have:

 var quizOne  =   FINLAND ;

I would expect to see:

 var quizOne  =   "FINLAND" ;

Secondly, the reason you have the current error appears a few times throughout your code.

You have:

if (var score = 5 || 4 )

This creates a problem as it is expecting an expression, but you have an assignment. Furthermore, the comparison here will not do exactly what you're thinking. You need to have score on both sides of the OR operator like so:

if(score == 5 || score == 4)

Finally, you have several else statements that seem to be floating around independently of any if clauses. An if else statement is written like this:

if(somethingIsTrue) { // if the expression is true
  // do code in here
} else {  // otherwise
   // do code in here
}

Hope this helps narrow down the bugs! :sparkles: