Home > Net >  I am struggle to figure out the reason why I got SyntaxError: Unexpected token '{' in node
I am struggle to figure out the reason why I got SyntaxError: Unexpected token '{' in node

Time:05-05

I am learning basic javascript now but stuck in this simple error because of syntax-error. It's ashamed to share my baby code but spend..more than an hours It looks ok for me... please help me

const readline = require('readline');
const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout,
});

let input = [];
let a;
let b;
// let C;
rl.on('line', (line) => {

  input = line.split(' ');
  
}).on('close', () => {
  
  a = input[0];
  b = input[1];
  
  if (a < b) {
    console.log('<');
  }else if (a > b) {
    console.log('>');
  }else (a == b) {
    console.log('=');
  };
});

// 1 2

CodePudding user response:

In the else statement you cannot put the condition. Replace your code with the below code.

const readline = require('readline');
const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout,
});

let input = [];
let a;
let b;
// let C;
rl.on('line', (line) => {

  input = line.split(' ');
  
}).on('close', () => {
  
  a = input[0];
  b = input[1];
  
  if (a < b) {
    console.log('<');
  }else if (a > b) {
    console.log('>');
  }else {
    console.log('=');
  };
});

Hope, it helps!! XD

  • Related