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

Code does not work in workspace.

Code is tested valid and working yet does not work in the workspace.

var q =["what is 2+2", "how many letters in red", "What color is the sky", "are hobos real?", "what is 3+3"],
    a =[4, 3, "blue", "yes", 6];

var correctAnswers=0;

for(var i=0; i<q.length ;i++){
  if(prompt(q[i])== a[i]){
    correctAnswers++;
  }
}
console.log(correctAnswers);
switch(correctAnswers){
    case 5:
      alert("You win the gold crown");
      break;
    case 4:
    case 3:
      alert("You win the silver crown");
      break;
    case 2:
    case 1:
      alert("You win the bronze crown");
      break;
    default:
      alert("You are Crownless!");

};
Ron McCranie
Ron McCranie
7,837 Points

I copied your code straight into a js file on one of my workspaces and it worked just fine. Could you share some more details of how your integrating it into your page, are you getting any errors, can you provide a share link to your workspace?

2 Answers

Artem Zverkovskiy
Artem Zverkovskiy
1,090 Points

Sometimes it happens. Just try to reboot your browser. In my case it helped.

Sean T. Unwin
Sean T. Unwin
28,690 Points

It works for me. I pasted your code into the workspace (a new one) provided for the video. I tried with Chrome Canary 42.0.2291.1 and Firefox 35.

Are you getting any errors in the console or what exactly is happening (or not) for you?