Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Pythagorean Theorem using custom functions in google sheets

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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!

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading