How the same logic works in c++ code but not in javascript code

Here are my both code. Notice that the c++ code got approved but the javascript one doesn’t.
It’s just a very basic problem of calculating sum from 1 to n number.

Problem: ADDNATRL Contest: CCSTART2

C++ solution:
#include <iostream>
using namespace std;

int main() {
	long long n;
	std::cin >> n;
	std::cout << n * (n + 1 ) / 2 ;
	return 0;
}

Javascript solution:
process.stdin.resume();
process.stdin.setEncoding('utf-8');
var arr = "";
process.stdin.on('data', function(chunk) {
arr += chunk;
});
process.stdin.on('end', function() {
arr = arr.split(" ");
var n = +arr[0];
var ans = n * (n+1) / 2;
process.stdout.write(ans.toString());
});

Can’t post link to my solution as it is ongoing contest. But ya it’s very basic question.

Maybe it’s something related to

/

giving integer or float, but I’m not too sure.

@patelmilanun Interestingly they are no AC JavaScript solutions😑