Help i dont know whats wrong with my code


Hi, i am currently on the Code Your Own Adventure 2! project and i believe i have wrote a correct Switch statement but every time i click save and submit code it says "Oops try again,Make sure you use a break statement with each case.
but the thing is.. I do and it keeps saying that & also the code outputs to the console so i know its working(If it is not please let me know). I even ran the code from the hint and it still came up could anyone take a look at my code and help me out please, Thank you. -Justin


Try adding indentation.


Your code is completely correct. It's not your fault :slight_smile:

You have to change this line:

console.log("case 1");

to something else, for example:

console.log("Case 1");

SCT system checks how many times you have used a case word in your code :smiley:


That's a kinda awkward way to check it, isn't it?


That's an understatement :slight_smile:

But on the other hand, this is a really nice programming challenge. With user code as a string, find the way to check if all the case statements have a break inside them. We assume that user code is correct.

I would start from removing all the string literals and then I would check if code goes in the pattern case, break, case, break... It also doesn't sound like a really great solution, right?

If someone has a better idea I would love to hear about it!

So I can slightly understand why they decided to test the code in this way :slight_smile:


Might be feasible to parse the code into an AST with some library and inspect that.. Just not plausible that it'll happen here.


you didnt add a break; after the default switch


I don't think that's required. I believe the problem was solved here:


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.