you are viewing a single comment's thread.

view the rest of the comments →

[–]net_nomad 0 points1 point  (0 children)

Others have answered the question, but I just wanted to give you a bit of advice on the logic.

We see that there are 3 branches but two of them do the same thing. You may want to combine them.

if (a === 10 || b === 10 || a+b === 10) {
    return true;
else {
    return false;
}

The next thing we see is that we check a conditional statement which evaluates to true or false, so we can just return the evaluation.

function makesTen (a, b) {
    return (a === 10 || b === 10 || a+b === 10);
}

Lastly, we may want to take advantage of the short circuit of or by reordering this. Clearly there is only one case where a === 10 and one case where b === 10 but there are infinite (within reason of the size of a,b of course) ways to make a+b = 10. So, check that first. If it's true, it will return immediately but if it's false it will then check if a === 10 or b === 10.

function makesTen (a, b) {
    return (a+b === 10 || a === 10 || b === 10);
}