Unable to understand the error

I’m stuck on Stage #EA6.

I’ve tried … (mention what you’ve tried so far).
I tried to implement lexical errors for unlisted chars for that I have added default case for handling the error scenarios. With the help of flag “isError” I am exiting with code “65”.

Here are my logs:
remote: [your_program] Logs from your program will appear here!
remote: [your_program] [line 1] Error: Unexpected character: =
remote: [your_program] EOF null
remote: [tester::#MP7] [test-1] expected exit code 0, got 65
remote: [tester::#MP7] [test-1] Test failed

And here's a snippet of my code: 
 (fileContent.length !== 0) {
  let lines = fileContent.split("\n");
  let isError = false;

  for (let i = 0; i < lines.length; i++) {
    for (let j = 0; j < lines[i].length; j++) {
      switch (lines[i][j]) {
        case "(":
          console.log("LEFT_PAREN ( null");
          break;
        case ")":
          console.log("RIGHT_PAREN ) null");
          break;
        case "{":
          console.log("LEFT_BRACE { null");
          break;
        case "}":
          console.log("RIGHT_BRACE } null");
          break;
        case "*":
          console.log("STAR * null");
          break;
        case ".":
          console.log("DOT . null");
          break;
        case ",":
          console.log("COMMA , null");
          break;
        case "+":
          console.log("PLUS + null");
          break;
        case "-":
          console.log("MINUS - null");
          break;
        case ";":
          console.log("SEMICOLON ; null");
          break;
        default:
          console.log(`[line ${i + 1}] Error: Unexpected character: ${lines[i][j]}`);
          isError = true;
          break;
      }
    }
  }
  console.log("EOF  null");
  if (isError) {
    process.exit(65);
  }
} else {
  console.log("EOF  null");
}

Hey,

Your console.log is actually telling you what is going on here:

This is because your switch doesn’t have a case for “=”, hence the above message printed by your console log here:

console.log('[line ${i + 1}] Error: Unexpected character: ${lines[i][j]}');

1 Like

I have added the case for “=” so the error was removed but I am getting warning for “==” now it says
remote: [tester::#MP7] [test-2] 𐄂 EQUAL = null
remote: [tester::#MP7] [test-2] Expected line #1 on stdout to be “EQUAL_EQUAL == null”, got “EQUAL = null”
remote: [tester::#MP7] [test-2] Test failed

I tried by adding the case to handle “==” but it still prints “EQUAL = null”. Is there anything that I am missing here

@DevRaahul Could you upload your code to GitHub and share the link? It will be much easier to debug if I can run it directly.

Closing this thread due to inactivity. If you still need assistance, feel free to reopen or start a new discussion!

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