inherit
Peabrained Codebreaker
107114
0
Mar 11, 2020 7:47:27 GMT -8
Boy_Wonder
6,249
July 2007
natzy24
|
Post by Boy_Wonder on Jun 14, 2014 6:11:40 GMT -8
Oh boy who let me code again I'm sure some people at thinking that at least, and I'm pretty sure its me being totally stupid. I'm trying to get something showing, and relying on using forms as an attempt to get used to making the admin panel UI values show in the components thingy. I've tested this with just using pure HTML append and it works, however its throwing an unexpected coding error for line 2... so if anyone can please point out where I did a thick (I am expecting it to be rather simple) $( document ).ready(function() {
var seasonPlugin == pb.plugin.get('seasonsDis');
var month = new Date().getMonth() + 1; // Month of year, 1 to 12
if ( month === 1 || month === 2 || month === 11 || month === 12 ) {
$( ".season" ).append('<img src="'+ seasonPlugin.settings.winter_image + '" /> <br /> ' +seasonPlugin.settings.winter_text +' ');
console.log ("It is Winter! Brrr!");
}
else if (month === 3 || month === 4 || month == 5){
$( ".season" ).append('<img src="'+ seasonPlugin.settings.spring_image + '" /> <br /> ' +seasonPlugin.settings.spring_text +' ');
console.log ("It is Spring! yay!");
}
else if (month === 6 || month=== 7 || month=== 8){
$( ".season" ).append('<img src="'+ seasonPlugin.settings.summer_image + '" /> <br /> ' + seasonPlugin.settings.summer_text +' ');
console.log ("It is summer, summer sun somethings begun");
}
else {
$( ".season" ).append('<img src="'+ seasonPlugin.settings.autumn_image + '" /> <br /> ' +seasonPlugin.settings.autumn_text +' ');
console.log ("Autumn is here and the leaves are falling");
}
console.log (month);
});
|
|
inherit
162752
0
Nov 7, 2024 3:58:23 GMT -8
Pebble
Where it all does or doesn't happen!
1,437
January 2011
pebbleleague
|
Post by Pebble on Jun 14, 2014 7:52:08 GMT -8
Remove one of the = from this line and see how it reacts!
var seasonPlugin == pb.plugin.get('seasonsDis');
It should be var variable = something;
EDIT: You also might want to shorten the if statements by changing them to something like this:
if ( month === 1 || month === 2 || month === 11 || month === 12 ) { To :
if ( month < 3 || month > 10 ) {
|
|
inherit
Peabrained Codebreaker
107114
0
Mar 11, 2020 7:47:27 GMT -8
Boy_Wonder
6,249
July 2007
natzy24
|
Post by Boy_Wonder on Jun 14, 2014 7:57:23 GMT -8
Can you explain how that would work - as I'm targetting specific months so that one targets January and February and then November and December and -idiot face- I SAID IT'D BE SOMETHING SIMPLE
|
|
inherit
173855
0
Apr 23, 2024 9:59:44 GMT -8
Texas
I check in every once in a while...
869
November 2011
petermaggio
|
Post by Texas on Jun 24, 2014 9:56:45 GMT -8
Boy_Wonder: I like to use number lines when I'm trying to visualize something like that. In the case of this: month === 1 || month === 2 || month === 11 || month === 12
If we create a number line 1 2 3 4 5 6 7 8 9 10 11 12
Then on your number line, you would have the things selected like so. 1 2 3 4 5 6 7 8 9 10 11 12 * * * *
Algebraically, the way you defined x would be like this: x = 1 or 2 or 11 or 12
However, there's a simpler way to do it. If your number set is [1-12] (inclusive) than you don't have to worry about accidentally have 13 or -1. Therefore, you can save some time by saying 3 > x < 10. This normally would include numbers greater than 13 or less than 0. But you by defining your "month" variable as a date, you restricted the possible values to 1-12. Therefore, by saying if( month < 3 || month > 10 )
You are essentially saying the same thing as if( month === 1 || month === 2 || month == 11 || month === 12)
Because month < 3 == 1 and 2, and month > 10 == 11 and 12. So, back to the number line (o means the number above is not included in the set) 1 2 3 4 5 6 7 8 9 10 11 12 ------o o---------
So instead of having to define each number, your defining a set of numbers. Hopefully that made sense.
|
|
inherit
Peabrained Codebreaker
107114
0
Mar 11, 2020 7:47:27 GMT -8
Boy_Wonder
6,249
July 2007
natzy24
|
Post by Boy_Wonder on Jun 24, 2014 10:57:10 GMT -8
That does make sense! I might fiddle with this some more in the next update
|
|