Help i dont know whats wrong with my code


#1

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


#2

Try adding indentation.


#3

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:


#4

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


#5

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:


#6

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


#7

you didnt add a break; after the default switch


#8

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


#9

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