Monday, May 10, 2021

Javascript Practice 42: JS Hero - Three identical values

 
Question: 

Write a function equals that checks 3 values for strict equality. The function should only return true if all 3 values are equal.

Example: equals(1, 1, 1) should return true and equals(1, 2, 1) should return false.




Answer: 

function equals (a,b,c) {

return a === b && a === c;

}; 

> declare a function equals
> it has 3 parameters
> the return statement is: a === b && a === c
> so the expression above will first check if a is strictly equal to b 
> then it will check if a is strictly equal to c
> if a is strictly equal to b and a is strictly equal to c then it will give a true statement 
> or else it will return false

No comments:

Post a Comment