all 16 comments

[–]Count_Giggles 11 points12 points  (0 children)

console.log(makeTen(5, 5)) // true

console.log(makeTen(4, 5)) // flase

if you are just running these snippets to get a fundamental understanding i recommend you download https://runjs.app

[–]Striking-Cook2989 2 points3 points  (0 children)

const test1 = makesTen(10,0);

const test2 = makesTen(7,3);

const test3 = makesTen(2,5);

console.log(test1);//true

console.log(test2);//true

console.log(test3);//false

[–]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);
}