Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

174
Views
I struggle to figure out the reason why I got SyntaxError: Unexpected token '{' in node.js

I am learning basic Javascript now but am stuck in this simple error because of syntax-error.

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
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

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

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!