Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pythagorus Calculator #348

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Calculators/Pythagorus Calculator/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
This is a pythagorus calculator, it takes two inputs from user from base, height and hypotenuse and gives the third value.<br>
It uses the well known theorem of Pythagorus theorem.<br>
e.g. hypotenuse^2 = base^2 + height^2
56 changes: 56 additions & 0 deletions Calculators/Pythagorus Calculator/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-+0n0xVW2eSR5OomGNYDnhzAbDsOXxcvSN1TPprVMTNDbiYZCxYbOOl7+AMvyTG2x" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.1/dist/js/bootstrap.bundle.min.js" integrity="sha384-gtEjrD/SeCtmISkJkNUaaKMoLD0//ElJ19smozuHV6z3Iehds+3Ulb9Bn9Plx0x4" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.9.2/dist/umd/popper.min.js" integrity="sha384-IQsoLXl5PILFhosVNubq5LC7Qb9DXgDA9i+tQ8Zj3iwWAwPtgFTxbJ8NT4GN1R8p" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.1/dist/js/bootstrap.min.js" integrity="sha384-Atwg2Pkwv9vp0ygtn1JAojH0nYbwNJLPhwyoVbhoPwBhjQPR5VtM2+xf0Uwh9KtT" crossorigin="anonymous"></script>
<link rel="stylesheet" href="style.css">
<title>Pythagorus Calculator</title>
</head>
<body>
<div class="heading">
<h1>Pythagorus Calculator</h1>
</div>

<div id = "primary">
<section class = "val1">
<input id="val1" name="val1" class="value" type = "number">
</section>

<section class = "unit1">
<select name="units1" id="units1">
<option id="unit1" value="base">Base</option>
<option id="unit1" value="height">Height</option>
<option id="unit1" value="hypotenuse">Hypotenuse</option>
</select>
</section>

<br>

<section class = "val2">
<input id="val2" name="val2" class="value" type = "number">
</section>

<section class = "unit2">
<select name="units2" id="units2">
<option id="unit2" value="base">Base</option>
<option id="unit2" value="height">Height</option>
<option id="unit2" value="hypotenuse">Hypotenuse</option>
</select>
</section>

<section class="button">
<button id="calculate" class="calculate" type="button">Calculate</button>
</section>

<p id="res">Welcome to Pythagorus Calculator </p>


</div>

<script src="index.js"></script>
</body>
</html>
40 changes: 40 additions & 0 deletions Calculators/Pythagorus Calculator/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
let result=0;
let temp=0;
let btn=document.getElementById("calculate");
btn.addEventListener("click",function(){
let val1=document.getElementById("val1").value;
let val2=document.getElementById("val2").value;
let input1=document.getElementById("units1").value;
let input2=document.getElementById("units2").value;
if(input1!="hypotenuse" && input2!="hypotenuse"){
result=Math.sqrt(Math.pow(val1,2)+Math.pow(val2,2));
temp=1;
}
else if(input1=="hypotenuse" && (input2=="height" || input2=="base")){
result=Math.sqrt(Math.pow(val1,2)-Math.pow(val2,2));
}
else if(input2=="hypotenuse" && (input1=="height" || input1=="base")){
result=Math.sqrt(Math.pow(val2,2)-Math.pow(val1,2));
}

if((input1=="height" || input2=="height") && (input1=="hypotenuse" || input2=="hypotenuse"))
temp=2;
if((input1=="base" || input2=="base") && (input1=="hypotenuse" || input2=="hypotenuse"))
temp=3;

switch(temp){
case 1:
document.getElementById("res").innerHTML="Hypotenuse is :"+result;
break;
case 2:
document.getElementById("res").innerHTML="Base is :"+result;
break;
case 3:
document.getElementById("res").innerHTML="Height is :"+result;
break;
default:
document.getElementById("res").innerHTML="Invalid Input";
break;
};
});

42 changes: 42 additions & 0 deletions Calculators/Pythagorus Calculator/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
body{
text-align:center;
background-color:blanchedalmond;
}

.button{
display:block;
margin:20px auto;
width:50%;
}

h1{
margin:70px;
font-family:verdana;
}

h3{
margin-top:30px;
color:black;
font-size:15px;
font-family:verdana;
}

input{
width:200px;
}

p{
margin-top:40px;
font-family:verdana;
font-size:15px;
display:inline-block;
}

section{
margin:20px 0px;
display:inline-block;
}

#res{
display:inline-block;
}