Lets Start this post with some useful notes/codes that I learned today: ( JavaScript with w3schools )
(1) Here is an example to join all the elements of an array into a string.
documents.write(var.join());
An example: If we want to have a + between the cars, the code would be :
documents.write(cars.join("+"));
(2') To remove the last element of an array we could use .pop().
An example: document.write(cars.pop());
(2") To remove the first element of an array we could use .shift().
(2'") To add an element to an array we could use .push("something").
(3) A cool thing to have in websites would be code that shows the date and the code is simply,
var date= new Date();
document.write(date);
Now knowing this lets program a clock for the V Programming Site !
[1] We need a function to get the date and then we need to get the hour,minutes and the seconds from the date().
function Time()
{
var today=new Date();
var h=today.getHours();
var m=today.getMinutes();
var s=today.getSeconds();
document.getElementById('txt').innerHTML=h+":"+m+":"+s;
t=setTimeout('Time()',500);
}
[2] But we would need the website to show 0# not # itself so we need another function.
m=check(m);
s=check(s);
function check(i){
if (i<10)
{
i="0" + i;
}
return i;
}
Now the result is:
(1) Here is an example to join all the elements of an array into a string.
documents.write(var.join());
An example: If we want to have a + between the cars, the code would be :
documents.write(cars.join("+"));
______________
An example: document.write(cars.pop());
(2") To remove the first element of an array we could use .shift().
(2'") To add an element to an array we could use .push("something").
______________
(3) A cool thing to have in websites would be code that shows the date and the code is simply,
var date= new Date();
document.write(date);
Now knowing this lets program a clock for the V Programming Site !
[1] We need a function to get the date and then we need to get the hour,minutes and the seconds from the date().
function Time()
{
var today=new Date();
var h=today.getHours();
var m=today.getMinutes();
var s=today.getSeconds();
document.getElementById('txt').innerHTML=h+":"+m+":"+s;
t=setTimeout('Time()',500);
}
[2] But we would need the website to show 0# not # itself so we need another function.
m=check(m);
s=check(s);
function check(i){
if (i<10)
{
i="0" + i;
}
return i;
}
Now the result is: