Hi guys I'm playing with a bit of JavaScript I'm trying to achieve that when the air quality goes to a specific level it will try to out put a text to Low High or medium or extreme
but when i set the numbers to the one below it ment to output GOOD but all i get is nothing i cant to to get my head around this any help plz
var aqi = rawdataextras[56];
if (Aqi=="1.0"){var air="Good";} else
if (Aqi=="1.1"){var air="Good";} else
if (Aqi=="1.2"){var air="Good";} else
if (Aqi=="1.3"){var air="Good";} else
if (Aqi=="1.4"){var air="Good";} else
if (Aqi=="1.5"){var air="Good";} else
if (Aqi=="1.6"){var air="Good";} else
if (Aqi=="1.7"){var air="Good";} else
if (Aqi=="1.8"){var air="Good";} else
if (Aqi=="1.9"){var air="Good";} else
{ var air="";}
}
else
{
$("#airquality").show();
}
$("#airquality").html("" + air);
Welcome to the Cumulus Support forum.
Latest Cumulus MX V4 release 4.0.1 (build 4023) - 16 May 2024
Latest Cumulus MX V3 release 3.28.6 (build 3283) - 21 March 2024
Legacy Cumulus 1 release 1.9.4 (build 1099) - 28 November 2014
(a patch is available for 1.9.4 build 1099 that extends the date range of drop-down menus to 2030)
Download the Software (Cumulus MX / Cumulus 1 and other related items) from the Wiki
Latest Cumulus MX V4 release 4.0.1 (build 4023) - 16 May 2024
Latest Cumulus MX V3 release 3.28.6 (build 3283) - 21 March 2024
Legacy Cumulus 1 release 1.9.4 (build 1099) - 28 November 2014
(a patch is available for 1.9.4 build 1099 that extends the date range of drop-down menus to 2030)
Download the Software (Cumulus MX / Cumulus 1 and other related items) from the Wiki
Air quality JavaScript
Moderator: daj
-
- Posts: 2502
- Joined: Wed 08 Jun 2011 11:19 am
- Weather Station: Davis Vantage Pro 2 + Ecowitt
- Operating System: GNU/Linux Ubuntu 22.04 LXC
- Location: Alcaston, Shropshire, UK
- Contact:
Re: Air quality JavaScript
Not 100% sure with JavaScript but it looks as if you are declaring the variable in the if/else blocks, so it will be out of scope by the time you use it. I think you need to declare it before your if/else and just set it inside the if/else block.
- HansR
- Posts: 6025
- Joined: Sat 20 Oct 2012 6:53 am
- Weather Station: GW1100 (WS80/WH40)
- Operating System: Raspberry OS/Bookworm
- Location: Wagenborgen (NL)
- Contact:
Re: Air quality JavaScript
@freddie, @dazza:
hmmm... Though not as it probably would have been taught at school (just declare it once) I don't think the declaration is the point here (var makes it global, let would have made it a local variable)
Apparently at the start - which is not shown here - the $("#airquality") is hidden because why else would you do a
Code: Select all
$("#airquality").show();
So the big question is: is it truly hidden at the start.
But to be honest: @dazza: go follow some (online) programming course. Many good (online) courses exist. I don't think the Cumulus forum is created with the purpose of being an education in JavaScript in mind and we are not equipped or educated as teachers (well some may be accidentally but you get it I hope).
Hans
https://meteo-wagenborgen.nl
CMX build 4017+ ● RPi 3B+ ● Raspbian Linux 6.1.21-v7+ armv7l ● dotnet 8.0.3
https://meteo-wagenborgen.nl
CMX build 4017+ ● RPi 3B+ ● Raspbian Linux 6.1.21-v7+ armv7l ● dotnet 8.0.3
-
- Posts: 2502
- Joined: Wed 08 Jun 2011 11:19 am
- Weather Station: Davis Vantage Pro 2 + Ecowitt
- Operating System: GNU/Linux Ubuntu 22.04 LXC
- Location: Alcaston, Shropshire, UK
- Contact:
Re: Air quality JavaScript
- dazza1223
- Posts: 867
- Joined: Sun 25 Jan 2015 8:41 pm
- Weather Station: Davis Vantage Pro 2 plus
- Operating System: Raspberry pi 4 (4gb)
- Location: Worthing
- Contact:
Re: Air quality JavaScript
Ok thank for the tips but I've sorted it out now just when back to it after a good night sleep then found out where I went wrong in the code meny thanks
- mcrossley
- Posts: 12902
- Joined: Thu 07 Jan 2010 9:44 pm
- Weather Station: Davis VP2/WLL
- Operating System: Bullseye Lite rPi
- Location: Wilmslow, Cheshire, UK
- Contact:
Re: Air quality JavaScript
My understanding...
var scopes to the enclosing function - or global if outside a function.
let scopes to the enclosing block - normally in an if, while, switch etc. - or the function if not in a block. If outside a function then the scope is the script.
vars are also 'hoisted', in that their declaration is moved to the top of the function scope at runtime. lets are not, they are initialised in-place.
var scopes to the enclosing function - or global if outside a function.
let scopes to the enclosing block - normally in an if, while, switch etc. - or the function if not in a block. If outside a function then the scope is the script.
vars are also 'hoisted', in that their declaration is moved to the top of the function scope at runtime. lets are not, they are initialised in-place.
- HansR
- Posts: 6025
- Joined: Sat 20 Oct 2012 6:53 am
- Weather Station: GW1100 (WS80/WH40)
- Operating System: Raspberry OS/Bookworm
- Location: Wagenborgen (NL)
- Contact:
Re: Air quality JavaScript
@mcrossley: yes, I was too short. I should have referred to the spec
Hans
https://meteo-wagenborgen.nl
CMX build 4017+ ● RPi 3B+ ● Raspbian Linux 6.1.21-v7+ armv7l ● dotnet 8.0.3
https://meteo-wagenborgen.nl
CMX build 4017+ ● RPi 3B+ ● Raspbian Linux 6.1.21-v7+ armv7l ● dotnet 8.0.3