29. What's wrong with my function?


I'm on exersise 29, and I think I messed up with my function.

var olderAge = function(person1, person2){
    if(person1.age = person2.age){
    else if(person1.age < person.age){
    else if(person2.age < person1.age){

I keep getting the error message :

SyntaxError: Unexpected token else

But I can't figure out where I might have made a mistake. If it would help, I can post the rest of the code.
Thanks in advance! :hearts:


I think that you don't need

the semicolons after your closing curly braces inside of the function. It might make the function malfunction. But post the rest of your code please! :slight_smile:

Also, the function doesn't need to be as complicated as you make it. Though there's nothing visibly wrong with your function, a simple if/else statement would suffice if you just wrote the if statements condition as person1.age being greater than person2.age than return person1.age and the else statement returning person2.age.

Last thing lol, lose the parenthesis after the return because in JS you don't need them! :slight_smile: You only need them after console.log and I know that can get confusing but just advice.


You need to remove the ';' after the last bracket


Thank you for your help! :slight_smile:

I know I'm not supposed to use them, but I like having them there so I can tell where it starts and ends. I guess I should just quit before it becomes too much of a habit, huh?


Thank you for your help! I'll take your advice! :slight_smile:


Technically I understand why you like having them there, but I do think that you shouldn't use them because not all editors, (outside of codecademy), will interpret them well. :slight_smile: Glad to help!


line 2 should't it be if(person1.age === person2.age){ instead of one = sign since we compare elements?


You're right, I noticed that after I tried to change it again. I really need to stop mixing those up.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.