I'm running into the below errors and I'm not quite sure as to why. Bare in mind, I'm using Node.js. The goal is to output the first 100 prime numbers to a 'hello.txt' file. Please advise how to get this working! Thanks.
return arr.join(“,”);
^
SyntaxError: Unexpected token ILLEGAL
at Module._compile (module.js:439:25)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:901:3
#!/usr/bin/env node
var prime = function (n) {
if (n === 2 || n === 3 || n === 5 || n === 7 || n === 11 || n === 13 || n === 17 || n === 19) {return n;}
if (n % 2 > 0 && n % 3 > 0 && n % 5 > 0 && n % 7 > 0 && n % 11 > 0 && n % 13 > 0 && n % 17 > 0 && n % 19 > 0 && n % Math.sqrt (n) > 0) {return n;}
};
var first100primes = function(k) {
var n = 1;
var arr = [];
for (n = 1; n < k+1; n++) {
arr.push(prime (n));
}
arr = arr.filter(Number);
arr.length=100;
return arr;
};
var fmt = function (arr) {
return arr.join(“,”);
};
var final = (fmt(first100primes(1000)));
var fs = require(‘fs’);
var outfile = “prime.txt”;
var out = final + “,”;
fs.writeFileSync(outfile, out);
console.log(“Script: ” + __filename + “\nWrote: ” + out + “To: ” + outfile);
“ is not the same as ". Similarly, ‘ and ' are not the same.
Change each occurance of “ and ‘ to " and ' respectively, and your code should work fine.