+ 7
Whats wrong with this code?😧
var date = new Date(); var day = date.getDay(); var hour = date.getHours(); var minute = date.getMinutes(); var seconds = date.getSeconds(); var days = new Array['Sunday','Monday','tuesday','wednesday','thursday','friday','saturday']; if(12 % hour < 12); { hour = hour + 'AM'; } Else { hour = hour + 'PM'; } document.write('Today is: '+ days[day] +' ,'+ 'Current time is:'+ hour+ ':' + minute+ ':'+seconds);
12 Answers
+ 29
Here's the right code.
var date = new Date();
var day = date.getDay();
var hour = date.getHours();
var minute = date.getMinutes();
var seconds = date.getSeconds();
var days = new Array('Sunday','Monday','tuesday','wednesday','thursday','friday','saturday');
if(12 % hour < 12)
{
hour = hour + 'AM';
}
else
{
hour = hour + 'PM';
}
document.write('Today is: '+ days[day] +' ,'+ 'Current time is:'+ hour+ ':' + minute+ ':'+seconds);
+ 11
скобки?! parentheses?!
+ 4
thank you... ☺
+ 4
@LeonardmcCoy: thank you for such an useful information... 😊
+ 3
ok u mean both are different... hmm but both work same or different...? sorry i am new in js.. i just copied it
+ 3
ok thanks@NavMen your information is very useful... ☺
+ 2
By the way, instead of hour = hour + 'AM', it is easier to write hour += 'AM', which will give you the same result.
+ 2
@NavMen: ok thanks but can u explain why should i not take an elements into[ ]
+ 1
well *I think* you should not take elements into square barackets after you do new Array
+ 1
@Learning because you are calling a class and it has a Constructor. In js, we use parantheses to call a class with the new keyword.
Examples to create an Array:
var arr = ["1 st item", "2 nd item"];
var arr = new Array("1 st item", "2 nd item");
+ 1
Actually it's very simple. There are two declarations of Arrays. They give the same result. One way to declare an Array is calling the Array class, and the other way is putting comma seperated items between square barackets. like i said, they give the same result
+ 1
Im glad if I could help