javascript - Palindrome program - unexpected identifier error -
i trying write js program print largest palindrome between 1 , 1000 (929). getting uncaught syntaxerror: unexpected identifier
on line 4 of code:
var num = 1; (var i=0;i<=1000;i++) { if == reverse(i) && isprime(i) num = i; console.log(num); } document.write(num); function reverse(s) { var o = ''; (var = s.length - 1; >= 0; i--) o += s[i]; return o; } function isprime(number) { var start = 2; while (start <= math.sqrt(number)) { if (number % start++ < 1) return false; } return number<=1 ? false : true; }
what uncaught syntaxerror: unexpected identifier
? , how fix bug?
your
if
statement missing parenthesis()
, block identifiers{}
.
the syntax javascript if
statement follows:
if (condition) { // } else { // else }
so, change if
code above , should good!
Comments
Post a Comment