Rob Battlebury
Rob Battlebury

Reputation: 3

Uncaught SyntaxError: Unexpected token else, completely stumped

if (monthsResult2 === 1) {
    monthsAppend = "month";
} else if (monthsResult2 > 1)
    monthsAppend = "months";
} else {
    monthsAppend = " ";           
}  

Can anyone tell me what the issue with the if/else statement is? I am currently getting the error:

Uncaught SyntaxError: Unexpected token else

But after looking at multiple examples I can't for the life of me see what I am doing wrong! Any help would be greatly appreciated!

Upvotes: 0

Views: 2176

Answers (2)

Tony
Tony

Reputation: 351

Ya forgot a { in your else if

if (monthsResult2 === 1) {
    monthsAppend = "month";
} else if (monthsResult2 > 1) {
    monthsAppend = "months";
} else {
    monthsAppend = " ";
}

Upvotes: 2

Radonirina Maminiaina
Radonirina Maminiaina

Reputation: 7004

You forget the open of the curly brace { in your else if.

else if (monthsResult2 > 1) 
                            ^
}

Try this:

if (monthsResult2 === 1) {
    monthsAppend = "month";
} else if (monthsResult2 > 1) {
    monthsAppend = "months";
} else {
    monthsAppend = " ";           
} 

Upvotes: 0

Related Questions