Tuesday, June 29, 2021

Junior Developer Central JS Practice Exercise - 01


Question:

Write a Javascript program to check two numbers and return true if one of the number is 100 or if the sum of the two numbers is 100.





Answer:

function check2nos (a,b) {

if (a === 100 || b === 100 || (a+b) === 100) {

return true;

} else { 

return false

}

};





> declare a function check2nos
> it has two parameters 'a' and 'b'
> we use an 'if / else statement' to check our conditions before we return the answer
> we have three major conditions to fulfil
>> we have to check if 'a' equals 100 or
>> we have to check if 'b' equals 100 or
>> we have to check if 'a + b' equals 100
> if any one of the above three conditions are met, then our program must return 'true
> else it should return false

No comments:

Post a Comment