'I struggle to figure out the reason why I got SyntaxError: Unexpected token '{' in node.js [closed]
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
Solution 1:[1]
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
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | ps2708 |
