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 Solution

Code feedback, code almost working! not registering all my code syntax

hey, so the code is works fine, well not really as the else if statements regarding the numbers eg if smaller than etc works but it only works if all answers correct and anything else gives me Silver stars, not bronze or 0 as I have written in my code. here is the code below, whats going on? why is it not registering the last few else if statements?

//answer starts with 0 score

var correctAnswers= 0


// 5 questions being asked  to the USER


var question1= prompt('What does OT stand for?'); 

var question2= prompt('What does ABA stand for?'); 

var question3= prompt('An ABA clinic is under the restriction of which government body?'); 

var question4= prompt('What is the name of the lead physician in County Moor Vix'); 

var question5= prompt('Is the OT considered a Doctor, i.e Doctor Stone '); 


//answers to questions, if correct adding +1 points

if (question1.toUpperCase()==='OCCUPATIONAL THERAPY'){


 correctAnswers +=1  ;

}

if (question2.toUpperCase()==='APPLIED BEHAVIOURAL ANALYSIS '){


correctAnswers +=1  ;

}

if (question3.toUpperCase()==='OFSTED'){


correctAnswers +=1  ;

}

if (question4.toUpperCase()==='DR STONE'){


correctAnswers +=1  ;

}

if (question5.toUpperCase()==='YES'){


correctAnswers +=1  ;

}


//assiging star color to amount of points, more points, better stars

if (correctAnswers === 5){ 

  alert ('YOU HAVE WON A GOLD STAR YA WARDA') 


} else if 

  (correctAnswers <= 3)  {
alert('You have won a silver star! better luck next time! ');



} else if 

  (correctAnswers <= 2)  {
alert('You have won a bronse star! better luck next time! ');

} else if 

  (correctAnswers === 0)  {
alert('You have won no stars bitch! better luck next time buddy ! ');

}





else 

{

alert('Oh no you bitch, better luck next time');
}


// output result in writing, confirming correct answers out of 5 


document.write('This is the number of correct answers = ' + correctAnswers + ' out of 5 ' );


```javascript

2 Answers

hello yasir.. you will always get 4 questions right even if there all right because of a an extra space

if (question2.toUpperCase()==='APPLIED BEHAVIOURAL ANALYSIS '){  // here is the extra space at the end
correctAnswers +=1  ;

// it should be
if (question2.toUpperCase()==='APPLIED BEHAVIOURAL ANALYSIS') // no spaces after ANALYSIS

you said it only gives you silver, no bronse or even if you get non of the questions right

if (correctAnswers === 5){ 
  alert ('YOU HAVE WON A GOLD STAR YA WARDA') 


// here you what you can is 
(correctAnswers >= 3)
// if the answer if 3 or 4 then this line will run if it is greater then 4 then the first line is going to run
} else if (correctAnswers <= 3)  {
alert('You have won a silver star! better luck next time! ');


(correctAnswers >= 1) // if the answer is 1 or 2 this line will run. if it is greater then the statement above will run
} else if (correctAnswers <= 2)  {
alert('You have won a bronse star! better luck next time! ');


// you can actually remove this last if else block and use the else here
// the else if statement above will run if the answer is 1.
// and the else block will run if the answer is less than 1. is this case if the answer is 0
} else if  (correctAnswers === 0)  {
alert('You have won no stars bitch! better luck next time buddy ! ');

}else {

alert('Oh no you bitch, better luck next time');
}

it will look like this

if (correctAnswers === 5) {

    alert('YOU HAVE WON A GOLD STAR YA WARDA')

} else if (correctAnswers >= 3) {
    alert('You have won a silver star! better luck next time! ');

} else if (correctAnswers >= 1) {
    alert('You have won a bronse star! better luck next time! ');

} else {
    alert('You have won no stars bitch! better luck next time buddy ! ');
}

i hope this helps

Thank you very much sir!