Syntaxerror: Unexpected Token { In Javascript
I am having an issue on my problem where the console is saying SyntaxError: Unexpected token { and I'm not sure where it's coming from. I am a JS newbie, just learning this stuff.
Solution 1:
I think you have a bug in your if...else part, try changing to this.
if (largestNumber) {
console.log(largestNumber);
} elseif (arr[i] != largestNumber) {
sumTotal += arr[i];
}
If this doesn't work comment me the full error you got. Try to inspect it in firebug console. Hope this helps you.
Solution 2:
Your code updated here....
var myArray = [4, 6, 23, 10, 1, 3];
var arrayAdditon = function (arr) {
var largestNumber = arr[0];
var sumTotal;
for (var i = 0; i < arr.length; i += 1) {
if (arr[i] > largestNumber) {
largestNumber = arr[i];
}
}
for (var j = 0; j < arr.length; j += 1) {
if (largestNumber) {
console.log(largestNumber);
} elseif (arr[i] != largestNumber) {
sumTotal += arr[i];
}
}
if (largestNumber === sumTotal) {
returntrue;
} else {
returnfalse;
}
};
Solution 3:
error in syntax else (arr[i] != largestNumber)
put if there
Solution 4:
I can not see a missing {
but
} else (arr[i] != largestNumber) {
sumTotal += arr[i];
}
should be
} elseif (arr[i] != largestNumber) {
sumTotal += arr[i];
}
Post a Comment for "Syntaxerror: Unexpected Token { In Javascript"