Skip to content

add Unit Converter project #189

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

Open
wants to merge 1 commit 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
1 change: 1 addition & 0 deletions Unit-Converter/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Unit-Converter
34 changes: 34 additions & 0 deletions Unit-Converter/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<!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="style.css" rel="stylesheet">
<title>Unit Converter</title>
</head>
<body>
<div class="container">
<div class="cont__1">
<p class="cont__1-text">Metric/Imperical Unit Conversion</p>
<input type="number" id="input" inputmode="numeric"><br>
<button id="convert_btn">Convert</button>
</div>
<div class="cont__2">
<div class="lenght">
<p class="cont__2-text1">Lenght (Meter/Feet)</p>
<p id="lenght_val"></p>
</div>
<div class="volume">
<p class="cont__2-text2">Volume (Liters/Gallons)</p>
<p id="volume_val"></p>
</div>
<div class="mass">
<p class="cont__2-text2">Mass (Kilograms/Pounds)</p>
<p id="mass_val"></p>
</div>
</div>
</div>
<script src="script.js"></script>
</body>
</html>
35 changes: 35 additions & 0 deletions Unit-Converter/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
const mtr = 3.281
const ltr = 0.264
const kgm = 2.204
const lenght = document.getElementById('lenght_val')
const volume = document.getElementById('volume_val')
const mass = document.getElementById('mass_val')
const input = document.getElementById('input')
const convertBtn = document.getElementById('convert_btn')

function convert(){
lenght.textContent=`${input.value} meters = ${(multiply(mtr))} feet | ${input.value} feet = ${(divide(mtr))} meters`
volume.textContent=`${input.value} liters= ${(multiply(ltr))} gallons | ${input.value} gallons = ${(divide(ltr))} liters`
mass.textContent=`${input.value} kilos = ${(multiply(kgm))} pounds | ${input.value} pounds = ${(divide(kgm))} kilos`

}
function multiply(val){
return ((input.value * val).toFixed(3))
}
function divide(val){
return ((input.value / val).toFixed(3))
}
input.addEventListener('input', resizeInput);
resizeInput.call(input);
function resizeInput() {
this.style.width = this.value.length + "ch";
}
input.addEventListener("keypress",function(e){
if(e.key==="Enter"){
convert()
}
})
convertBtn.addEventListener('click',function(){
convert()
})

79 changes: 79 additions & 0 deletions Unit-Converter/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
body {
margin: 0;
background-color: gray;
display: flex;
justify-content: center;
margin-top: 50px;
text-align: center;
}

.container{
border: 5px solid white;
box-shadow: 10000px black;
background-color: rgba(32,41,56,255);
border-radius: 10px;
height: 500px;
width: 400px;

}
.cont__1{
background-color: rgba(106,67,255,255);
border-radius: 5px 5px 0px 0px;
width: 400px;
margin-bottom: 0px;
height:40%;
}
.cont__1-text{
margin-top: 0px;
padding-top:40px ;
color: white;
text-transform: uppercase;
}
#convert_btn{
background: white;
color:black ;
padding: 5px;
width: 80px;
border: none;
border-radius: 5px;
}
.cont__2{
display: grid;
justify-content: center;
background-color: rgba(244,244,244,255);
padding-top: 30px;
height: 270px;
border-radius: 0px 0px 5px 5px;
}
.lenght,.volume,.mass{
background: white;
width: 350px;
height: 4rem;
margin-bottom: 20px;
}
#lenght_val,#volume_val,#mass_val{
margin-top: 10px;
font-size: 10px;
}
.cont__2-text1,.cont__2-text2,.text-4{
color: rgba(139,136,156,255);
margin-bottom: 10px;
font-weight: bolder;
font-size: 15px;
}



#input{
font-size:1.3em;
padding:8px 25px;
margin: 20px 0px;
background: transparent;
color: white;
border:1px solid white;
}
input[type=number]::-webkit-inner-spin-button,
input[type=number]::-webkit-outer-spin-button {
-webkit-appearance: none;
margin: 0;
}