Regarding the project2(weather api)

//here’s my code,am unable to get the output could you please help…

Suma

Default text

Submit

Hi @kariyamsumasree we are not able to see your your code , can you attach it properly so we can point out the issue.

Hi @kariyamsumasree please share it in text format so we can directly copy it and can check.

<!DOCTYPE html>
<html>
<head>
<title>Suma</title>

</head>
<body>
<p id="output">Default text</p>
<input id="city">
<button onclick="update_user()">Submit</button>
<script type="text/javascript">
function show_temp(){
document.getElementById("output").style.color="red";
document.getElementById("output").style.fontSize="20px";
city=document.getElementById("city").value;
httpRequest=new XMLHttpRequest();
url="https://api.weatherbit.io/v2.0/current?city="+city+"&key=88ed3bb27c9b462d910835adbed8cf45";
httpRequest.open("GET",url);
httpRequest.send();

httpRequest.onreadystatechange=function(){
if(this.readyState==4 && this.status == 200)
   {
user_data= JSON.parse(this.responseText);
document.getElementById("output").innerHTML=user_data.data[0].temp;
}
}
}
</script>
</body>
</html>

Hi @kariyamsumasree Use the code that i have attached in the below link- Project -2 weather forcasting - #4 by himanshu.arya

Do let me know if it helps and also try to check with different browser if not works.

Sure but … may i know the mistake in my code.

Hi @kariyamsumasree To find the error we need js , css and html code also . The changes need to do in your code as you attached in your query document.getElementById("output").innerHTML= "The temperature in " + city_name + " is " + weather_data.data[0].temp + "°F"; }
The last line of the your code.

1 Like