Lowest price ever! Learn Generative AI for 48% less!
Get my discount0
Write a JavaScript program to check two numbers and return true if one of the number is 100 or if the the sum of the two numbers
const isEqualTo100 = (a,b) => a === 100 || b === 100 || (a+b) === 100; Is this Correct?
3 Answers
+ 7
take this as an opportunity to learn testing and debugging.
run the code with different values and see if it yields expected results. try at least 5 tests
if it does then yes, 98% chance it's right. no then you need to check it
+ 6
cool you checked! :)
You see || is OR so if a === 100 then the whole thing is true.
And in your post you put
return true IF ONE is 100.
a is 100 so true, correct
and you said OR if the sum of the two numbers
saying or means if a is 100 then it doesnt matter if the sum is 100 or not
+ 1
I checked with this values.
console.log(isEqualTo100(100,0));
console.log(isEqualTo100(0,100));
console.log(isEqualTo100(10,0));
console.log(isEqualTo100(0,10));
console.log(isEqualTo100(50,50));
console.log(isEqualTo100(40,60));
console.log(isEqualTo100(100,100));
I'm getting this result:
true
true
false
false
true
true
true // I have problem with this result it should be false because both are 100 ?