Jump to content

JavaScript need help

robeng
Go to solution Solved by Guest,

Your forgot the month of Mai, or May. 

You only have 11 months listed and it's the 12th month. 

Hi! I have a problem with my code. We got a task to do a clock. With year, month, time etc. I got everything to work exept for one thing. It does't show the month, it shows undefined. I have created a month array called "månadLista" with all of the month in it. And then i have a variable called månad with equals the month of my computer. So what i have done is that i want to write out the month. I have done it like this månadLista[månad]. So it calles the array "månadLista" and for the item in the list witch is månad. Here is all of my code:

//Variabler:
var månadLista = ["Januari", "Februari", "Mars", "April", "Juni", "July", "Augusti", "September", "Oktober", "November", "December"];
//Functioner
function sverigesTid() {
    var datum = new Date();
    var årtal = datum.getFullYear();
    var månad = datum.getMonth();
    var dag = datum.getDate();
    var timmar = datum.getHours();
    var minuter = datum.getMinutes();
    var sekunder = datum.getSeconds();
    document.getElementById("stockholmDatum").innerHTML = årtal + "-" + månadLista[månad] + "-" + dag;
    document.getElementById("stockholmTid").innerHTML = timmar + ":" + minuter + ":" + sekunder;
}
function londonTid() {
    var datum = new Date();
    var årtal = datum.getFullYear();
    var månad = datum.getMonth();
    var dag = datum.getDay();
    var timmar = datum.getHours();
    var minuter = datum.getMinutes();
    var sekunder = datum.getSeconds();
    document.getElementById("londonDatum").innerHTML = årtal + "-" + månadLista[månad] + "-" + dag;
    document.getElementById("londonTid").innerHTML = (timmar-1) + ":" + minuter + ":" + sekunder;
}
//Kalla på functioner
setInterval("sverigesTid()" , 1000);
setInterval("londonTid()" , 1000);

So in short. How do i fix so that the month get displayed and not undefined at månadLista[månad].

Thanks in advance!

Link to comment
Share on other sites

Link to post
Share on other sites

Your forgot the month of Mai, or May. 

You only have 11 months listed and it's the 12th month. 

Link to comment
Share on other sites

Link to post
Share on other sites

6 minutes ago, fpo said:

Your forgot the month of Mai, or May. 

You only have 11 months listed and it's the 12th month. 

Ohh... Thanks! :)

Link to comment
Share on other sites

Link to post
Share on other sites

On 2016-12-14 at 5:30 PM, Niemand said:

Is that Swedish? It looks cool.

Yup!

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×