Skip to content

Added celsius To Fahrenheit Button #6

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: master
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 .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"liveServer.settings.port": 5501
}
55 changes: 43 additions & 12 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ const descElement = document.querySelector(".temperature-description p");
const locationElement = document.querySelector(".location p");
const notificationElement = document.querySelector(".notification");


var searchButton = document.querySelector('.search-btn');
var cityInput = document.querySelector('.city-input');
var currentCity = document.getElementById('city-name');




// App data
const weather = {};

Expand Down Expand Up @@ -63,6 +71,34 @@ function getWeather(latitude, longitude){
});
}





var getCityCoordinates = function() {
var cityName = cityInput.value.trim();
if (!cityName) return;
var queryURL = "http://api.openweathermap.org/geo/1.0/direct?q=" + cityName + "&limit=1&appid=" + APIKey;


fetch(queryURL)
.then(function(response) {
return response.json();
})
.then(function(data){
// console.log(data);
if(!data.length) return alert("No coordinates found for " + cityName + "!");
var { name, lat, lon} = data[0];
get5DayWeather(name, lat, lon);
currentCity.innerHTML = data[0].name
getCurrentWeather(name, lat, lon);
}).catch(function() {
alert("Can not get corridnates!")
});
}
searchButton.addEventListener('click', getCityCoordinates);


// DISPLAY WEATHER TO UI
function displayWeather(){
iconElement.innerHTML = `<img src="icons/${weather.iconId}.png"/>`;
Expand All @@ -76,19 +112,14 @@ function celsiusToFahrenheit(temperature){
return (temperature * 9/5) + 32;
}

// WHEN THE USER CLICKS ON THE TEMPERATURE ELEMENET
tempElement.addEventListener("click", function(){
if(weather.temperature.value === undefined) return;

if(weather.temperature.unit == "celsius"){
let fahrenheit = celsiusToFahrenheit(weather.temperature.value);

function Tempretureconverter(){
let fahrenheit = celsiusToFahrenheit(weather.temperature.value);
fahrenheit = Math.floor(fahrenheit);

tempElement.innerHTML = `${fahrenheit}°<span>F</span>`;
weather.temperature.unit = "fahrenheit";
}else{
tempElement.innerHTML = `${weather.temperature.value}°<span>C</span>`;
weather.temperature.unit = "celsius"
}
});

}



39 changes: 23 additions & 16 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,33 @@
<body>

<div class="container">
<div class="app-title">
<p>Weather</p>
</div>
<div class="notification"> </div>
<div class="weather-container">
<div class="weather-icon">
<img src="icons/unknown.png" alt="">
</div>
<div class="temperature-value">
<p>- °<span>C</span></p>
<div class="contentcenter">
<div class="app-title">
<p>Weather</p>
</div>
<div class="temperature-description">
<p> - </p>
</div>
<div class="location">
<p>-</p>
<!-- <div class="notification"> </div> -->
<div class="weather-container">
<div class="weather-icon">
<img src="icons/unknown.png" alt="">
</div>
<div class="temperature-value">
<p>- °<span>C</span></p>
</div>
<div class="temperature-description">
<p> - </p>
</div>
<div class="location">
<p>-</p>
</div>
</div>

<button class="ctofbutton" onclick="Tempretureconverter()">celsius To Fahrenheit</button>
</div>
</div>





<script src="app.js"></script>
</body>
</html>
Expand Down
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "c",
"version": "1.0.0",
"description": "Hi Everyone!",
"main": "app.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC"
}
25 changes: 21 additions & 4 deletions style.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@
}

body{
background-color: #293251;
background-color:skyblue;
margin: auto;
}

.container{
width: 300px;
width: 800px;
background-color: #FFF;

display: block;
/* display: block; */

margin: 0 auto;

border-radius: 10px;
Expand All @@ -21,6 +23,7 @@ body{
width: 300px;
height: 50px;
border-radius: 10px 10px 0 0;
margin: auto;
}

.app-title p{
Expand All @@ -47,6 +50,7 @@ body{
.weather-container{
width: 300px;
height: 260px;
margin: auto;
background-color: #F4F9FF;
}

Expand All @@ -73,7 +77,20 @@ body{
text-align: center;
cursor: pointer;
}

.ctofbutton{
margin: 10px auto;
display: flex;
width: 200px;
height: 40px;
align-items: center;
justify-content: center;
font-size: 16px;
background-color: lightgreen;
border-style: none;
}
.ctofbutton:hover{
background-color:lightseagreen;
}
.temperature-value p:hover{

}
Expand Down