Monday, May 10, 2021

Javascript Practice 46: JS Hero - if

 
Question: 

Write a function equals that checks two values for strict equality. If the two values are equal, the string 'EQUAL' should be returned. If they are unequal, you should get 'UNEQUAL'.

Example: equals(1, 1) should return 'EQUAL' and equals(1, 2) should return 'UNEQUAL'.




Answer: 

function equals (a,b) {

if (a === b) {

return 'EQUAL';

} else {

return 'UNEQUAL';}

}; 

> declare a function equals 
> it has 2 parameters
> it uses if / else statements to execute a block of code
> if a is strictly equal to b then the function would return 'Equal' or else 'Unequal

No comments:

Post a Comment