Passing Objects into Functions - there is a HUGE error - makers didn't consider possible negative values


#1

in funciton var ageDifference = function(person1, person2) {
return person1.age - person2.age;
}
should be smth like if (persons1.age > person2.age){
return person1.age - person2.age}
else{return person2.age-person1.age};

because if you ask: "hey guys, what's the age difference between you" you do not get the answer -5.
:o) :wink:


#2

In your function put the JS function abs(), like this:


var ageDifference - function(person1, person2){
    return abs(person1.age - person2.age);
};

Hope this helps. :wink:


#3

That seems like it would work well with the "abs()" function. Try that as awk suggested and see if that doesn't solve your issue.

@awk888, a tip to make your code look a little more like eye candy (because you seem like a very helpful individual) would be to do this.

```
<code here>
```

It'll make your code look like this.

var ageDifference - function(person1, person2){
 return abs(person1.age - person2.age);
};

Otherwise very well done! :+1:


#5

thx guys!

absolute value - of course :wink:

it would be great if someone changed it (add it to) in tutorial.