I am trying to make pythagorean theorem using custom functions in google sheets. I want it to be able to find any missing side by doing =PYTH(a,b,c). here is my current code:
function PYTH(a,b,c){
if(c = 0){return(Math.sqrt(Math.pow(a, 2)+Math.pow(b, 2)))};
if(b = 0){return(Math.sqrt(Math.pow(c, 2)-Math.pow(a, 2)))};
if(a = 0){return(Math.sqrt(Math.pow(c, 2)-Math.pow(b, 2)))};
};
I have tried using if functions to see when something is missing by checking if they equal "" and checking if they equal 0.
>Solution :
So it looks like you have the logic correct and it should work, however there is one small detail you missed.
Here is a functional version.
function PYTH(a,b,c){
if(c == 0){return(Math.sqrt(Math.pow(a, 2)+Math.pow(b, 2)))};
if(b == 0){return(Math.sqrt(Math.pow(c, 2)-Math.pow(a, 2)))};
if(a == 0){return(Math.sqrt(Math.pow(c, 2)-Math.pow(b, 2)))};
};
For the if statements when comparing the variables to 0, you need double or triple "=" signs to do the comparison.
Hope this helps!