I have the folowing code:
var windowNow = window.localStorage.getItem("windowNow");
switch(windowNow)
{
case 1:
var link = "http://www.zive.sk/rss/sc-47/default.aspx";
var listviewID = "feedZive";
break;
case 2:
var link = "http://mobilmania.azet.sk/rss/sc-47/default.aspx";
var listviewID = "feedMobil";
break;
case 3:
var link = "http://www.automoto.sk/rss";
var listviewID = "feedAuto";
break;
}
and I know that windowNow === 1 because I have checked it with alert and also to be sure that it realy is 1 I checked it with if(windowNow == 1) { alert ("Window now is 1");} and it worked. But it is not working inside my switch (checked it with alerts).
The items in the localStorage are always strings. Use case "1" and so on.
The problem with your check is that is a loose check, which doesn't check for the data type. You should have tried
if(windowNow === 1) { alert ("Window now is 1");}
Notice the triple =.
Do not declare variables inside a switch. Declare them outside the switch and assign inside. Also convert to an integer first.
var windowNow = parseInt(window.localStorage.getItem("windowNow"), 10), link, listviewID;
switch(windowNow)
{
case 1:
link = "http://www.zive.sk/rss/sc-47/default.aspx";
listviewID = "feedZive";
break;
case 2:
link = "http://mobilmania.azet.sk/rss/sc-47/default.aspx";
listviewID = "feedMobil";
break;
case 3:
link = "http://www.automoto.sk/rss";
listviewID = "feedAuto";
break;
default:
// default assignment.
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With