+ 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);

21st Mar 2018, 10:33 AM
R (V👸Rani).💃😘
R (V👸Rani).💃😘 - avatar
12 odpowiedzi
+ 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);
21st Mar 2018, 10:39 AM
Igor Makarsky
Igor Makarsky - avatar
+ 11
скобки?! parentheses?!
21st Mar 2018, 11:49 AM
アルゴリズム X
アルゴリズム X - avatar
+ 4
thank you... ☺
21st Mar 2018, 10:40 AM
R (V👸Rani).💃😘
R (V👸Rani).💃😘 - avatar
+ 4
@LeonardmcCoy: thank you for such an useful information... 😊
21st Mar 2018, 4:05 PM
R (V👸Rani).💃😘
R (V👸Rani).💃😘 - avatar
+ 3
ok u mean both are different... hmm but both work same or different...? sorry i am new in js.. i just copied it
21st Mar 2018, 5:12 PM
R (V👸Rani).💃😘
R (V👸Rani).💃😘 - avatar
+ 3
ok thanks@NavMen your information is very useful... ☺
21st Mar 2018, 5:19 PM
R (V👸Rani).💃😘
R (V👸Rani).💃😘 - avatar
+ 2
By the way, instead of hour = hour + 'AM', it is easier to write hour += 'AM', which will give you the same result.
21st Mar 2018, 3:42 PM
LeonardMcCoy
LeonardMcCoy - avatar
+ 2
@NavMen: ok thanks but can u explain why should i not take an elements into[ ]
21st Mar 2018, 5:04 PM
R (V👸Rani).💃😘
R (V👸Rani).💃😘 - avatar
+ 1
well *I think* you should not take elements into square barackets after you do new Array
21st Mar 2018, 5:01 PM
NavMen
+ 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");
21st Mar 2018, 5:09 PM
NavMen
+ 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
21st Mar 2018, 5:15 PM
NavMen
+ 1
Im glad if I could help
21st Mar 2018, 5:25 PM
NavMen