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

This is my solution:

let answers = [
  {
   Study: "JavaScript",
   Old: 23,
   Hobby: "Swimming",
   Language: "English",
   Drive: "No"
  }
];

let answersCount = 5;
let correctAnswers = 0;
let questionLeft = '['+answersCount+ ' questions left]';



let askStudy = prompt("What do you study? " + questionLeft);

answersCount -=1;
questionLeft = '['+answersCount+ ' questions left]';
let askOld = prompt("How old are you? " + questionLeft);

answersCount -=1;
questionLeft = '['+answersCount+ ' questions left]';
let askHobby = prompt("What is your hobby? " + questionLeft);

answersCount -=1;
questionLeft = '['+answersCount+ ' questions left]';
let askLang = prompt("What language do you speak ? " + questionLeft);

answersCount -=1;
questionLeft = '['+answersCount+ ' questions left]';
let askDrive = prompt("Do you like driving? " + questionLeft);



for(i = 0; i < answers.length; i++) {

  if(askStudy.toLowerCase() === answers[i].Study.toLowerCase()) {
    correctAnswers += 1;
  } if (parseInt(askOld) === answers[i].Old) {
    correctAnswers += 1;
  } if (askLang.toLowerCase() === answers[i].Language.toLowerCase()) {
    correctAnswers += 1;
  } if (askDrive.toLowerCase() === answers[i].Drive.toLowerCase()) {
    correctAnswers += 1;
  } if (askHobby.toLowerCase() === answers[i].Hobby.toLowerCase()) {
    correctAnswers += 1;
  }
}

if(correctAnswers === 5) {
  document.write("<h2>Congrats! You've just won gold crown!</h2>");
}

if(correctAnswers === 3 ||correctAnswers === 4) {
  document.write("<h2>Congrats! You've just won silver crown!</h2>");
}

if(correctAnswers === 1 ||correctAnswers === 2) {
  document.write("<h2>Congrats! You've just won bronze crown!</h2>");
}

if(correctAnswers === 0) {
  document.write("<h2>Sorry! you didn't win anything try again later!</h2>");
}