Please paste your errors as comments into this gist. Paste both your code and the error message.
-
-
Save airportyh/05452978247e322d8df6fc232d90a228 to your computer and use it in GitHub Desktop.
Uncaught SyntaxError: Invalid regular expression: missing / fib1.html:26
var belowFourMil = true;
var a = 1;
var b = 2;
var sum = 0;
var temp = 0;
while(belowFourMil){
//a, b, temp
var temp = a + b;
a = b; // set previous to recent
b = temp; //Set recent to the new number
/ need to check if temp id divisible by 2
if(temp % 2 === 0){
sum += temp;
}
if(temp > 4000000){
belowFourMil = false;
}
}
console.log(sum);
var a = 10;
function makeError(){
for(var i=0; i<=a; i++){
a.push(i);
}
}
makeError();
TypeError: a.push is not a function
at makeError:26:7
at eval:30:1
at eval
var arr;
console.log(arr.length);
Uncaught TypeError: Cannot read property 'length' of undefined
at sort-alg.html:80
scripts.js:80 Uncaught SyntaxError: Unexpected token else
if(stock.Change.indexOf('+') > -1 )
var classChange = "success";
}else{
Uncaught TypeError: i is not a function(…)
function factorial(n) {
var total = 0;
var formula = '';
for (var i = n; i >= 1; i--) {
total = total + i;
if (formula === '') {
formula = i.toString();
}
else {
formula = formula + '+' + i();
}
console.log(formula);
}
console.log(total);
}
factorial(3);
person.friends[0].name.length
// __ __
// | \\\ /__\
// |.\\\ \ //--.i
// i \\\\ \ ///// i
// i \\\\\ \ _______ //////:|
// i.\\\\\\ --|i | i|-- /////.|
// |:\\\\ |||:i i iiii| /// i
// \ \ / i|i | |||i\ i
// / :| || i i| i i
// | |: i | | |i| \
// i | || | i i| i
// | / | : | \\ i
// | // __ :.:: __ \ i
// | / _\ / _\ i
// | | # \ # \ i
// i ___--| \_) \_)--___ |
// i==== \__/ \__/ ====|
// i== ==|
// i- _-_ -i
// /| \ / i
// // \ _ _ --- | -- _ /
// / _\- - _-- | --_ --_ /
// / - \_ _- _- | -- -_ /_
// / _ -\_ -- -__/ \__- -_ _/_ -
// // - _---__ \___/ --__/_ -
// _- -_
console.time('countPrimes');
countPrimes(2000000);
console.timeEnd('countPrimes');
function countPrimes(num) {
var knownPrimes = [2,3,5];
var sum = 0;
for (var i = 6; i < num; i++) {
if((i % 2 != 0) && (i % 3 != 0) && (i % 5 != 0)) {
for (var j = 0; j < knownPrimes.length; j++) {
if (i % knownPrimes[j] == 0) {
beak;
}
if ((j == (knownPrimes.length - 1) ) && (i % knownPrimes[j] != 0)) {
knownPrimes.push(i);
}
}
}
}
sum = knownPrimes.reduce(function(a,b){
return a + b;
},0);
console.log(sum);
}
X - Uncaught SyntaxError: Unexpected identifier script.js:2
find-prime.html:43 Uncaught TypeError: Assignment to constant variable.
at getPrime (find-prime.html:43)
at find-prime.html:55
--Code--
function getPrime(n){
var prime = []; //We will stash all our prime numbers here.
prime.push(2); //Start with a 2 as it's the first prime number.
// console.log(prime);
var i = 2; //start checking at 2++
while(prime.length < n){ //Keep going until we have pushed n prime numbers on (=nth prime)
i++;
const isPrime = true; //Assume the number is prime until we find otherwise
for(var j = 0; j < prime.length; j++){ //Divide the current number by every known prime.
var iByJ = i % prime[j];
if(iByJ == 0){ //this thing is not prime. We know, because it divided evenly into something.
isPrime = false; //update the boolean
break; //don't waste any time looking for more. it's not prime. leave the loop
}
}
if(isPrime){
prime.push(i);
}
// console.log(prime);
}
return i;
}
console.log(getPrime(6));