<html>
<head>
<title>Struktur Data Linked List</title></head>
<body>
<script language = "JavaScript">
<!--
function LinkedList()
{
this._panjang = 0;
this._kepala = null;
}
LinkedList.prototype =
{
constructor: LinkedList,
//Membuat Metode Untuk Menambah Data kedalam List
Tambah: function (data)
{
//Membuat Node List
var node = { data: data, next: null }, NodeTanda;
//Periksa Isi List
if (this._kepala === null)
{
this._kepala = node;
}
else
{
NodeTanda = this._kepala;
while (NodeTanda.next)
{
NodeTanda = NodeTanda.next;
}
NodeTanda.next = node;
}
this._panjang++;
},
//Membuat Metode Untuk Menunjuk Item Data
Item: function(index)
{
if (index > -1 && index < this._panjang)
{
var NodeTanda = this._kepala,
i = 0;
while (i++ < index)
{
NodeTanda = NodeTanda.next;
}
return NodeTanda.data;
}
else
{
return null;
}
},
//Membuat Metode Untuk Membuang Elemen List
Buang: function(index)
{
if (index > -1 && index < this._panjang)
{
var NodeTanda = this._kepala, previous, i = 0;
if (index === 0)
{
this._kepala = NodeTanda.next;
}
else
{
while(i++ < index)
{
previous = NodeTanda;
NodeTanda = NodeTanda.next;
}
previous.next = NodeTanda.next;
}
this._panjang--;
return NodeTanda.data;
}
else
{
return null;
}
},
//Membuat Metode Untuk Mengetahui Jumlah Elemen List
Ukuran: function()
{
return this._panjang;
},
//Membuat Metode Untuk Membentuk Array
toArray: function()
{
var result = [],
NodeTanda = this._kepala;
while(NodeTanda){
result.push(NodeTanda.data);
NodeTanda = NodeTanda.next;
}
return result;
},
//Membuat Metode Untuk Konversi ke String
toString: function()
{
return this.toArray().toString();
},
var list = new LinkedList();
list.Tambah("Teknik Informatika");
list.Tambah("Teknik Komputer");
list.Tambah("Komputerisasi Akuntansi");
list.Tambah("Computer Networking");
document.write("Isi LinkedList <br>");
document.write("--------------- <br>");
for (i=0; i<4; i++)
{
document.write(list.Item(i) + "<br>") ;
}
document.write("---------------- <br>");
alert("Isi LinkedList Awal =" + list.Item(0));
alert("Item 1 pada Linked list dibuang, yaitu = " +list.Item(1));
list.Buang(1);
document.write("Isi LinkedList Terakhir <br>");
document.write("--------------- <br>");
for (i=0; i<4; i++)
{
document.write(list.Item(i) + "<br>") ;
}
document.write("--------------- <br>");
//-->
</script>
</body>
</html>
Rabu, 20 Mei 2009
Queue
<html>
<head>
<title>Struktur Data Queue</title>
<script language="JavaScript">
var queue = new Array();
function Masuk_Antrian(data)
{
queue.unshift(data);
}
function Keluar_Antrian()
{
var yang_keluar_antrian = queue.pop();
if (queue.length==0)
return "Antrian Sudah Kosong";
else
return yang_keluar_antrian;
}
function Dalam_Antrian(list)
{
list.options.length=0;
for (var i = 0; i<queue.length; i++)
{
var data = new Option(queue[i]);
list.options[list.options.length] = data;
}
}
</script>
</head>
<body>
<form>
<input type=text name=textSimpan>
<input type=button value="Masuk Antrian"
onclick='Masuk_Antrian(textSimpan.value);
textSimpan.value="";
Dalam_Antrian(Visualisasi);'>
<select name="Visualisasi" size=12>
<option>Isi Antrian....
</select>
<input type=text name=textAmbil size=20>
<input type=button value="Keluar Antrian"
onClick="textAmbil.value=Keluar_Antrian();
Dalam_Antrian(Visualisasi);">
</form>
</body>
</html>
<head>
<title>Struktur Data Queue</title>
<script language="JavaScript">
var queue = new Array();
function Masuk_Antrian(data)
{
queue.unshift(data);
}
function Keluar_Antrian()
{
var yang_keluar_antrian = queue.pop();
if (queue.length==0)
return "Antrian Sudah Kosong";
else
return yang_keluar_antrian;
}
function Dalam_Antrian(list)
{
list.options.length=0;
for (var i = 0; i<queue.length; i++)
{
var data = new Option(queue[i]);
list.options[list.options.length] = data;
}
}
</script>
</head>
<body>
<form>
<input type=text name=textSimpan>
<input type=button value="Masuk Antrian"
onclick='Masuk_Antrian(textSimpan.value);
textSimpan.value="";
Dalam_Antrian(Visualisasi);'>
<select name="Visualisasi" size=12>
<option>Isi Antrian....
</select>
<input type=text name=textAmbil size=20>
<input type=button value="Keluar Antrian"
onClick="textAmbil.value=Keluar_Antrian();
Dalam_Antrian(Visualisasi);">
</form>
</body>
</html>
Queueu pake shift
<html>
<head>
</title>Program Queue dengan shift dan unshift javascript</title>
<script language= "JavaScript">
function DataQueue()
{
var queue = []
queue.unshift(1);
queue.unshift(2);
var i = queue.shift();
document.write(i + "<br />");
queue.unshift(3);
queue.unshift(4);
var i = queue.shift();
document.write(i + "<br />");
}
</script>
</head>
<body>
<form name="FormStrukturData">
<input name="btnQueue" value="Queue" type="button"
onClick="DataQueue();" />
</form>
</body>
<html>
<head>
</title>Program Queue dengan shift dan unshift javascript</title>
<script language= "JavaScript">
function DataQueue()
{
var queue = []
queue.unshift(1);
queue.unshift(2);
var i = queue.shift();
document.write(i + "<br />");
queue.unshift(3);
queue.unshift(4);
var i = queue.shift();
document.write(i + "<br />");
}
</script>
</head>
<body>
<form name="FormStrukturData">
<input name="btnQueue" value="Queue" type="button"
onClick="DataQueue();" />
</form>
</body>
<html>
Queue pake POP
<html>
<head>
</title>Program Queue dengan shift dan unshift javascript</title>
<script language= "JavaScript">
function DataQueue()
{
var queue = []
queue.unshift(1);
queue.unshift(2);
var i = queue.shift();
document.write(i + "<br />");
queue.unshift(3);
queue.unshift(4);
var i = queue.pop();
document.write(i + "<br />");
}
</script>
</head>
<body>
<form name="FormStrukturData">
<input name="btnQueue" value="Queue" type="button"
onClick="DataQueue();" />
</form>
</body>
<html>
<html>
<head>
</title>Program Queue dengan shift dan unshift javascript</title>
<script language= "JavaScript">
function DataQueue()
{
var queue = []
queue.unshift(1);
queue.unshift(2);
var i = queue.shift();
document.write(i + "<br />");
queue.unshift(3);
queue.unshift(4);
var i = queue.pop();
document.write(i + "<br />");
}
</script>
</head>
<body>
<form name="FormStrukturData">
<input name="btnQueue" value="Queue" type="button"
onClick="DataQueue();" />
</form>
</body>
<html>
<head>
</title>Program Queue dengan shift dan unshift javascript</title>
<script language= "JavaScript">
function DataQueue()
{
var queue = []
queue.unshift(1);
queue.unshift(2);
var i = queue.shift();
document.write(i + "<br />");
queue.unshift(3);
queue.unshift(4);
var i = queue.pop();
document.write(i + "<br />");
}
</script>
</head>
<body>
<form name="FormStrukturData">
<input name="btnQueue" value="Queue" type="button"
onClick="DataQueue();" />
</form>
</body>
<html>
<html>
<head>
</title>Program Queue dengan shift dan unshift javascript</title>
<script language= "JavaScript">
function DataQueue()
{
var queue = []
queue.unshift(1);
queue.unshift(2);
var i = queue.shift();
document.write(i + "<br />");
queue.unshift(3);
queue.unshift(4);
var i = queue.pop();
document.write(i + "<br />");
}
</script>
</head>
<body>
<form name="FormStrukturData">
<input name="btnQueue" value="Queue" type="button"
onClick="DataQueue();" />
</form>
</body>
<html>
Sabtu, 09 Mei 2009
SEBELUM KITA MENGELUH...........
1. Hari ini sebelum kamu mengatakan kata-kata yang tidak baik, pikirkan tentang seseorang yang tidak dapat berbicara sama sekali.
2. Sebelum kamu mengeluh tentang rasa dari makananmu, pikirkan tentang seseorang yang tidak punya apapun untuk dimakan.
3. Sebelum anda mengeluh tidak punya apa-apa, pikirkan tentang seseorang yang meminta-minta di jalanan.
4. Sebelum kamu mengeluh bahwa kamu buruk, pikirkan tentang seseorang yang berada pada tingkat yang terburuk di dalam hidupnya.
5. Sebelum kamu mengeluh tentang suami atau istrimu, pikirkan tentang seseorang yang memohon kepada Allah untuk diberikan teman hidup.
6. Hari ini sebelum kamu mengeluh tentang hidupmu, pikirkan tentang seseorang yang meninggal terlalu cepat.
7. Sebelum kamu mengeluh tentang anak-anakmu, pikirkan tentang seseorang yang sangat ingin mempunyai anak tetapi dirinya mandul.
8. Sebelum kamu mengeluh tentang rumahmu yang kotor karena pembantumu tidak mengerjakan tugasnya, pikirkan tentang orang-orang yang tinggal dijalanan.
9. Sebelum kamu mengeluh tentang jauhnya kamu telah menyetir, pikirkan tentang seseorang yang menempuh jarak yang sama dengan berjalan.
10. Dan disaat kamu lelah dan mengeluh tentang pekerjaanmu, pikirkan tentang pengangguran, orang-orang cacat yang berharap mereka mempunyai pekerjaan seperti anda.
11. Sebelum kamu menunjukkan jari dan menyalahkan orang lain, ingatlah bahwa tidak ada seorangpun yang tidak berdosa.
2. Sebelum kamu mengeluh tentang rasa dari makananmu, pikirkan tentang seseorang yang tidak punya apapun untuk dimakan.
3. Sebelum anda mengeluh tidak punya apa-apa, pikirkan tentang seseorang yang meminta-minta di jalanan.
4. Sebelum kamu mengeluh bahwa kamu buruk, pikirkan tentang seseorang yang berada pada tingkat yang terburuk di dalam hidupnya.
5. Sebelum kamu mengeluh tentang suami atau istrimu, pikirkan tentang seseorang yang memohon kepada Allah untuk diberikan teman hidup.
6. Hari ini sebelum kamu mengeluh tentang hidupmu, pikirkan tentang seseorang yang meninggal terlalu cepat.
7. Sebelum kamu mengeluh tentang anak-anakmu, pikirkan tentang seseorang yang sangat ingin mempunyai anak tetapi dirinya mandul.
8. Sebelum kamu mengeluh tentang rumahmu yang kotor karena pembantumu tidak mengerjakan tugasnya, pikirkan tentang orang-orang yang tinggal dijalanan.
9. Sebelum kamu mengeluh tentang jauhnya kamu telah menyetir, pikirkan tentang seseorang yang menempuh jarak yang sama dengan berjalan.
10. Dan disaat kamu lelah dan mengeluh tentang pekerjaanmu, pikirkan tentang pengangguran, orang-orang cacat yang berharap mereka mempunyai pekerjaan seperti anda.
11. Sebelum kamu menunjukkan jari dan menyalahkan orang lain, ingatlah bahwa tidak ada seorangpun yang tidak berdosa.
Pengalaman Adalah Ilmu Yang Tak Terharga
" TIADA HIDUP TANPA KEGAGALAN ,KEKALAHAN , DAN KEJATUHAN............
AIR SUNGAI MENUJU LAUT MELEWATI JALAN YANG BERLIKU......
BERDIRILAH TEGAK KEMBALI.............................
JANGAN MEMANDANG KE BELAKANG , MASA LALU TELAH BERLALU....................
HIDUP BERJALAN TERUS............................
LANGIT YANG ABADI TETAP TIDAK BERUBAH DAN HIDUP BAGAIKAN BENTUKAN GERAKAN AWAN DI ANGKASA YANG SELALU BERUBAH-UBAH TIDAK MEMILIKI KETETAPAN DAN TIDAK ABADI . "
"CAHAYA MENTARI BILA DIFOKUSKAN AKAN MEMBAKAR KERTAS " Dedidulur@yahoo.co.id
AIR SUNGAI MENUJU LAUT MELEWATI JALAN YANG BERLIKU......
BERDIRILAH TEGAK KEMBALI.............................
JANGAN MEMANDANG KE BELAKANG , MASA LALU TELAH BERLALU....................
HIDUP BERJALAN TERUS............................
LANGIT YANG ABADI TETAP TIDAK BERUBAH DAN HIDUP BAGAIKAN BENTUKAN GERAKAN AWAN DI ANGKASA YANG SELALU BERUBAH-UBAH TIDAK MEMILIKI KETETAPAN DAN TIDAK ABADI . "
"CAHAYA MENTARI BILA DIFOKUSKAN AKAN MEMBAKAR KERTAS " Dedidulur@yahoo.co.id
Algoritma Torbo Fascal
ALGORITMA PENGHITUNGAN MATRIK PERKALIAN
Program Jumlah_matriks;
Uses Wincrt;
Var matA, matB, Matc : Array [1..20, 1..20] of Integer;
I,J,K : Integer ;
brsA , klmA : Integer ;
brsB, klmb : Integer;
Begin
clrscr ;
brsA := 3; klmA :=3 ;
brsB := 3; klmB :=3;
{input elemen matriks A'}
writeln ( ' masukan data matrik A :');
for I := 1 to brsA do
for j := 1 to klmB do
Begin
write ('A[',I,',',J,'] = ');
readln (matA[I,J])
end;
{ Input elemen Matriks A' }
writeln (' Masukan data Matrik B :');
For I := 1 to brsB do
for J := 1 to klmA do
begin
write ('B [',I,',',J,'] =');
readln (matB[I,J] )
end;
writeln ('proses Perkalian matriks....');
write (' tekan ENTER untuk melihat hasilnya....');
For I := 1 to brsA do
for J := 1 to klmB do
BEGIN
matC [I,J] := 0;
For K := 1 to brsB do
matC [I,J] := matC [I,J] + matA [I,K] * matB [K,J];
end;
readln;
clrscr;
{tampil Matriks A}
writeln (' matriks A = ');
for I := 1 to brsA do
Begin
for j := 1 to klmA do
write ( matA[I,J] : 3);
Writeln;
End;
Writeln;
{ tampil matriks B}
writeln (' matriks B= ');
for I := 1 to brsB do
begin
fOR j := 1 to klmB do
write (matB[I,J] : 3);
writeln;
end;
writeln;
{ Tampil Matriks C }
writeln ( ' matriks C = ');
for I := 1 to brsA do
begin
for j := 1 to klmB do
write (matC [I,j] :3);
writeln;
end;
readln;
end.
Jum,banyak,rata-rata bilangan
Program Looping_01;
Uses Wincrt;
Var
Bilangan, Jumlah, i,n: Integer;
Rata_rata : real;
Begin
Jumlah := 0;
i:= 1 ;
Write ( 'MASUKAN BANYAKNYA BILANGAN:');
Readln (N) ;
Writeln;
While i <= N do
Begin
Write (' Bilangan -',i,'=');
readln ( bilangan);
Jumlah := Jumlah + Bilangan;
i := i+1;
End;
rata_rata := Jumlah / N;
Writeln;
Writeln (' BANYAKNYA BILANGAN :',Jumlah : 5);
Writeln (' JUMLAH BILANGAN ;', N:5);
Writeln (' RATA - RATA BILANGAN :', rata_rata :5:2);
End.
Lulus >60
Program menghitung_kelulusan;
Uses Wincrt;
Var
Nilai : Real;
ket : String;
Begin
write ('MASUKAN SEBUAH NILAI:');
Readln (Nilai);
IF Nilai > 60 Then
Ket:= 'lulus'
Else
Ket := ' tidak lulus';
Write (ket);
End.
Bo2t nilai,ket,nilai hurup
Program Jumlah_case;
uses wincrt;
var
Nilai : Integer;
begin
Write('Masukan Nilai :');
readln(nilai);
case nilai of
80..100 : begin
writeln('Juara : 1');
writeln('Hadiah : Mobil');
writeln('Uang Saku : Rp.10.000 000');
end;
70..79 : begin
writeln('Juara : 2');
writeln('Hadiah : Motor');
writeln('Uang Saku : Rp.7.000 000');
end;
60..69 : begin
writeln('Juara : 3');
writeln('Hadiah : Kulkas');
writeln('Uang Saku : Rp.5.000 000');
end;
50..59 : begin
writeln('Juara : 4');
writeln('Hadiah : Mesin Cuci');
writeln('Uang Saku : Rp.5.000 000');
end;
40..49 : begin
writeln('Juara : 5');
writeln('Hadiah : TV');
writeln('Uang Saku : Rp.2.500 000');
end;
0..40 : begin
writeln('Juara : 6');
writeln('Hadiah : Radio Aktif');
writeln('Uang Saku : Rp.2.000 000');
end;
else write('NILAI YANG ANDA MASUKAN SALAH');
end;
end.
Program Jumlah_matriks;
Uses Wincrt;
Var matA, matB, Matc : Array [1..20, 1..20] of Integer;
I,J,K : Integer ;
brsA , klmA : Integer ;
brsB, klmb : Integer;
Begin
clrscr ;
brsA := 3; klmA :=3 ;
brsB := 3; klmB :=3;
{input elemen matriks A'}
writeln ( ' masukan data matrik A :');
for I := 1 to brsA do
for j := 1 to klmB do
Begin
write ('A[',I,',',J,'] = ');
readln (matA[I,J])
end;
{ Input elemen Matriks A' }
writeln (' Masukan data Matrik B :');
For I := 1 to brsB do
for J := 1 to klmA do
begin
write ('B [',I,',',J,'] =');
readln (matB[I,J] )
end;
writeln ('proses Perkalian matriks....');
write (' tekan ENTER untuk melihat hasilnya....');
For I := 1 to brsA do
for J := 1 to klmB do
BEGIN
matC [I,J] := 0;
For K := 1 to brsB do
matC [I,J] := matC [I,J] + matA [I,K] * matB [K,J];
end;
readln;
clrscr;
{tampil Matriks A}
writeln (' matriks A = ');
for I := 1 to brsA do
Begin
for j := 1 to klmA do
write ( matA[I,J] : 3);
Writeln;
End;
Writeln;
{ tampil matriks B}
writeln (' matriks B= ');
for I := 1 to brsB do
begin
fOR j := 1 to klmB do
write (matB[I,J] : 3);
writeln;
end;
writeln;
{ Tampil Matriks C }
writeln ( ' matriks C = ');
for I := 1 to brsA do
begin
for j := 1 to klmB do
write (matC [I,j] :3);
writeln;
end;
readln;
end.
Jum,banyak,rata-rata bilangan
Program Looping_01;
Uses Wincrt;
Var
Bilangan, Jumlah, i,n: Integer;
Rata_rata : real;
Begin
Jumlah := 0;
i:= 1 ;
Write ( 'MASUKAN BANYAKNYA BILANGAN:');
Readln (N) ;
Writeln;
While i <= N do
Begin
Write (' Bilangan -',i,'=');
readln ( bilangan);
Jumlah := Jumlah + Bilangan;
i := i+1;
End;
rata_rata := Jumlah / N;
Writeln;
Writeln (' BANYAKNYA BILANGAN :',Jumlah : 5);
Writeln (' JUMLAH BILANGAN ;', N:5);
Writeln (' RATA - RATA BILANGAN :', rata_rata :5:2);
End.
Lulus >60
Program menghitung_kelulusan;
Uses Wincrt;
Var
Nilai : Real;
ket : String;
Begin
write ('MASUKAN SEBUAH NILAI:');
Readln (Nilai);
IF Nilai > 60 Then
Ket:= 'lulus'
Else
Ket := ' tidak lulus';
Write (ket);
End.
Bo2t nilai,ket,nilai hurup
Program Jumlah_case;
uses wincrt;
var
Nilai : Integer;
begin
Write('Masukan Nilai :');
readln(nilai);
case nilai of
80..100 : begin
writeln('Juara : 1');
writeln('Hadiah : Mobil');
writeln('Uang Saku : Rp.10.000 000');
end;
70..79 : begin
writeln('Juara : 2');
writeln('Hadiah : Motor');
writeln('Uang Saku : Rp.7.000 000');
end;
60..69 : begin
writeln('Juara : 3');
writeln('Hadiah : Kulkas');
writeln('Uang Saku : Rp.5.000 000');
end;
50..59 : begin
writeln('Juara : 4');
writeln('Hadiah : Mesin Cuci');
writeln('Uang Saku : Rp.5.000 000');
end;
40..49 : begin
writeln('Juara : 5');
writeln('Hadiah : TV');
writeln('Uang Saku : Rp.2.500 000');
end;
0..40 : begin
writeln('Juara : 6');
writeln('Hadiah : Radio Aktif');
writeln('Uang Saku : Rp.2.000 000');
end;
else write('NILAI YANG ANDA MASUKAN SALAH');
end;
end.
Tugas Kalender
<script>
setCal()
function getTime() {
// initialize time-related variables with current time settings
var now = new Date()
var hour = now.getHours()
var minute = now.getMinutes()
now = null
var ampm = ""
// validate hour values and set value of ampm
if (hour >= 12) {
hour -= 12
ampm = "PM"
} else
ampm = "AM"
hour = (hour == 0) ? 12 : hour
// add zero digit to a one digit minute
if (minute < 10)
minute = "0" + minute // do not parse this number!
// return time string
return hour + ":" + minute + " " + ampm
}
function leapYear(year) {
if (year % 4 == 0) // basic rule
return true // is leap year
/* else */ // else not needed when statement is "return"
return false // is not leap year
}
function getDays(month, year) {
// create array to hold number of days in each month
var ar = new Array(12)
ar[0] = 31 // January
ar[1] = (leapYear(year)) ? 29 : 28 // February
ar[2] = 31 // March
ar[3] = 30 // April
ar[4] = 31 // May
ar[5] = 30 // June
ar[6] = 31 // July
ar[7] = 31 // August
ar[8] = 30 // September
ar[9] = 31 // October
ar[10] = 30 // November
ar[11] = 31 // December
// return number of days in the specified month (parameter)
return ar[month]
}
function getMonthName(month) {
// create array to hold name of each month
var ar = new Array(12)
ar[0] = "January"
ar[1] = "February"
ar[2] = "March"
ar[3] = "April"
ar[4] = "May"
ar[5] = "June"
ar[6] = "July"
ar[7] = "August"
ar[8] = "September"
ar[9] = "October"
ar[10] = "November"
ar[11] = "December"
// return name of specified month (parameter)
return ar[month]
}
function setCal() {
// standard time attributes
var now = new Date()
var year = now.getYear()
if (year < 1000)
year+=1900
var month = now.getMonth()
var monthName = getMonthName(month)
var date = now.getDate()
now = null
// create instance of first day of month, and extract the day on which it occurs
var firstDayInstance = new Date(year, month, 1)
var firstDay = firstDayInstance.getDay()
firstDayInstance = null
// number of days in current month
var days = getDays(month, year)
// call function to draw calendar
drawCal(firstDay + 1, days, date, monthName, year)
}
function drawCal(firstDay, lastDate, date, monthName, year) {
// constant table settings
var headerHeight = 50 // height of the table's header cell
var border = 2 // 3D height of table's border
var cellspacing = 4 // width of table's border
var headerColor = "midnightblue" // color of table's header
var headerSize = "+3" // size of tables header font
var colWidth = 60 // width of columns in table
var dayCellHeight = 25 // height of cells containing days of the week
var dayColor = "darkblue" // color of font representing week days
var cellHeight = 40 // height of cells representing dates in the calendar
var todayColor = "red" // color specifying today's date in the calendar
var timeColor = "purple" // color of font representing current time
// create basic table structure
var text = "" // initialize accumulative variable to empty string
text += '<CENTER>'
text += '<TABLE BORDER=' + border + ' CELLSPACING=' + cellspacing + '>' // table settings
text += '<TH COLSPAN=7 HEIGHT=' + headerHeight + '>' // create table header cell
text += '<FONT COLOR="' + headerColor + '" SIZE=' + headerSize + '>' // set font for table header
text += monthName + ' ' + year
text += '</FONT>' // close table header's font settings
text += '</TH>' // close header cell
// variables to hold constant settings
var openCol = '<TD WIDTH=' + colWidth + ' HEIGHT=' + dayCellHeight + '>'
openCol += '<FONT COLOR="' + dayColor + '">'
var closeCol = '</FONT></TD>'
// create array of abbreviated day names
var weekDay = new Array(7)
weekDay[0] = "Sun"
weekDay[1] = "Mon"
weekDay[2] = "Tues"
weekDay[3] = "Wed"
weekDay[4] = "Thu"
weekDay[5] = "Fri"
weekDay[6] = "Sat"
// create first row of table to set column width and specify week day
text += '<TR ALIGN="center" VALIGN="center">'
for (var dayNum = 0; dayNum < 7; ++dayNum) {
text += openCol + weekDay[dayNum] + closeCol
}
text += '</TR>'
// declaration and initialization of two variables to help with tables
var digit = 1
var curCell = 1
for (var row = 1; row <= Math.ceil((lastDate + firstDay - 1) / 7); ++row) {
text += '<TR ALIGN="right" VALIGN="top">'
for (var col = 1; col <= 7; ++col) {
if (digit > lastDate)
break
if (curCell < firstDay) {
text += '<TD></TD>';
curCell++
} else {
if (digit == date) { // current cell represent today's date
text += '<TD HEIGHT=' + cellHeight + '>'
text += '<FONT COLOR="' + todayColor + '">'
text += digit
text += '</FONT><BR>'
text += '<FONT COLOR="' + timeColor + '" SIZE=2>'
text += '<CENTER>' + getTime() + '</CENTER>'
text += '</FONT>'
text += '</TD>'
} else
text += '<TD HEIGHT=' + cellHeight + '>' + digit + '</TD>'
digit++
}
}
text += '</TR>'
}
// close all basic table tags
text += '</TABLE>'
text += '</CENTER>'
// print accumulative HTML string
document.write(text)
}
</script>
<p align="center"><font face="arial" size="-2">This free script provided by</font><br>
<font face="arial, helvetica" size="-2"><a href="http://javascriptkit.com">JavaScript
Kit</a></font></p>
setCal()
function getTime() {
// initialize time-related variables with current time settings
var now = new Date()
var hour = now.getHours()
var minute = now.getMinutes()
now = null
var ampm = ""
// validate hour values and set value of ampm
if (hour >= 12) {
hour -= 12
ampm = "PM"
} else
ampm = "AM"
hour = (hour == 0) ? 12 : hour
// add zero digit to a one digit minute
if (minute < 10)
minute = "0" + minute // do not parse this number!
// return time string
return hour + ":" + minute + " " + ampm
}
function leapYear(year) {
if (year % 4 == 0) // basic rule
return true // is leap year
/* else */ // else not needed when statement is "return"
return false // is not leap year
}
function getDays(month, year) {
// create array to hold number of days in each month
var ar = new Array(12)
ar[0] = 31 // January
ar[1] = (leapYear(year)) ? 29 : 28 // February
ar[2] = 31 // March
ar[3] = 30 // April
ar[4] = 31 // May
ar[5] = 30 // June
ar[6] = 31 // July
ar[7] = 31 // August
ar[8] = 30 // September
ar[9] = 31 // October
ar[10] = 30 // November
ar[11] = 31 // December
// return number of days in the specified month (parameter)
return ar[month]
}
function getMonthName(month) {
// create array to hold name of each month
var ar = new Array(12)
ar[0] = "January"
ar[1] = "February"
ar[2] = "March"
ar[3] = "April"
ar[4] = "May"
ar[5] = "June"
ar[6] = "July"
ar[7] = "August"
ar[8] = "September"
ar[9] = "October"
ar[10] = "November"
ar[11] = "December"
// return name of specified month (parameter)
return ar[month]
}
function setCal() {
// standard time attributes
var now = new Date()
var year = now.getYear()
if (year < 1000)
year+=1900
var month = now.getMonth()
var monthName = getMonthName(month)
var date = now.getDate()
now = null
// create instance of first day of month, and extract the day on which it occurs
var firstDayInstance = new Date(year, month, 1)
var firstDay = firstDayInstance.getDay()
firstDayInstance = null
// number of days in current month
var days = getDays(month, year)
// call function to draw calendar
drawCal(firstDay + 1, days, date, monthName, year)
}
function drawCal(firstDay, lastDate, date, monthName, year) {
// constant table settings
var headerHeight = 50 // height of the table's header cell
var border = 2 // 3D height of table's border
var cellspacing = 4 // width of table's border
var headerColor = "midnightblue" // color of table's header
var headerSize = "+3" // size of tables header font
var colWidth = 60 // width of columns in table
var dayCellHeight = 25 // height of cells containing days of the week
var dayColor = "darkblue" // color of font representing week days
var cellHeight = 40 // height of cells representing dates in the calendar
var todayColor = "red" // color specifying today's date in the calendar
var timeColor = "purple" // color of font representing current time
// create basic table structure
var text = "" // initialize accumulative variable to empty string
text += '<CENTER>'
text += '<TABLE BORDER=' + border + ' CELLSPACING=' + cellspacing + '>' // table settings
text += '<TH COLSPAN=7 HEIGHT=' + headerHeight + '>' // create table header cell
text += '<FONT COLOR="' + headerColor + '" SIZE=' + headerSize + '>' // set font for table header
text += monthName + ' ' + year
text += '</FONT>' // close table header's font settings
text += '</TH>' // close header cell
// variables to hold constant settings
var openCol = '<TD WIDTH=' + colWidth + ' HEIGHT=' + dayCellHeight + '>'
openCol += '<FONT COLOR="' + dayColor + '">'
var closeCol = '</FONT></TD>'
// create array of abbreviated day names
var weekDay = new Array(7)
weekDay[0] = "Sun"
weekDay[1] = "Mon"
weekDay[2] = "Tues"
weekDay[3] = "Wed"
weekDay[4] = "Thu"
weekDay[5] = "Fri"
weekDay[6] = "Sat"
// create first row of table to set column width and specify week day
text += '<TR ALIGN="center" VALIGN="center">'
for (var dayNum = 0; dayNum < 7; ++dayNum) {
text += openCol + weekDay[dayNum] + closeCol
}
text += '</TR>'
// declaration and initialization of two variables to help with tables
var digit = 1
var curCell = 1
for (var row = 1; row <= Math.ceil((lastDate + firstDay - 1) / 7); ++row) {
text += '<TR ALIGN="right" VALIGN="top">'
for (var col = 1; col <= 7; ++col) {
if (digit > lastDate)
break
if (curCell < firstDay) {
text += '<TD></TD>';
curCell++
} else {
if (digit == date) { // current cell represent today's date
text += '<TD HEIGHT=' + cellHeight + '>'
text += '<FONT COLOR="' + todayColor + '">'
text += digit
text += '</FONT><BR>'
text += '<FONT COLOR="' + timeColor + '" SIZE=2>'
text += '<CENTER>' + getTime() + '</CENTER>'
text += '</FONT>'
text += '</TD>'
} else
text += '<TD HEIGHT=' + cellHeight + '>' + digit + '</TD>'
digit++
}
}
text += '</TR>'
}
// close all basic table tags
text += '</TABLE>'
text += '</CENTER>'
// print accumulative HTML string
document.write(text)
}
</script>
<p align="center"><font face="arial" size="-2">This free script provided by</font><br>
<font face="arial, helvetica" size="-2"><a href="http://javascriptkit.com">JavaScript
Kit</a></font></p>
Minggu, 03 Mei 2009
Hari_Array
<html>
<head>
<title>Program Hari</title>
</head>
<body>
<script language = "JavaScript">
<!--
var Hari = new Array();
angka = parseInt(prompt("Masukan Angka 1-7 =\n"));
Hari[0] = "Senin";
Hari[1] = "Selasa";
Hari[2] = "Rabu";
Hari[3] = "Kamis";
Hari[4] = "Jumat";
Hari[5] = "Sabtu";
Hari[6] = "Minggu";
if ( angka==1)
document.write(Hari[0]);
if ( angka==2)
document.write(Hari[1]);
if ( angka==3)
document.write(Hari[2]);
if ( angka==4)
document.write(Hari[3]);
if ( angka==5)
document.write(Hari[4]);
if ( angka==6)
document.write(Hari[5]);
if ( angka==7)
document.write(Hari[6]);
//-->
</script>
</body>
<html>
<head>
<title>Program Hari</title>
</head>
<body>
<script language = "JavaScript">
<!--
var Hari = new Array();
angka = parseInt(prompt("Masukan Angka 1-7 =\n"));
Hari[0] = "Senin";
Hari[1] = "Selasa";
Hari[2] = "Rabu";
Hari[3] = "Kamis";
Hari[4] = "Jumat";
Hari[5] = "Sabtu";
Hari[6] = "Minggu";
if ( angka==1)
document.write(Hari[0]);
if ( angka==2)
document.write(Hari[1]);
if ( angka==3)
document.write(Hari[2]);
if ( angka==4)
document.write(Hari[3]);
if ( angka==5)
document.write(Hari[4]);
if ( angka==6)
document.write(Hari[5]);
if ( angka==7)
document.write(Hari[6]);
//-->
</script>
</body>
<html>
Sabtu, 02 Mei 2009
Bulan JS
<html>
<head>
<title>Program Bulan</title>
</head>
<body>
<script language = "JavaScript">
<!--
var bulan = new Array();
angka = parseInt(prompt("Masukan Angka 1-12 =\n"));
bulan[0] = "Januari";
bulan[1] = "Februari";
bulan[2] = "Maret";
bulan[3] = "April";
bulan[4] = "Mei";
bulan[5] = "Juni";
bulan[6] = "Juli";
bulan[7] = "Agustus";
bulan[8] = "September";
bulan[9] = "Oktober";
bulan[10] = "November";
bulan[11] = "Desember";
if ( angka==1)
document.write(bulan[0]);
if ( angka==2)
document.write(bulan[1]);
if ( angka==3)
document.write(bulan[2]);
if ( angka==4)
document.write(bulan[3]);
if ( angka==5)
document.write(bulan[4]);
if ( angka==6)
document.write(bulan[5]);
if ( angka==7)
document.write(bulan[6]);
if ( angka==8)
document.write(bulan[7]);
if ( angka==9)
document.write(bulan[8]);
if ( angka==10)
document.write(bulan[9]);
if ( angka==11)
document.write(bulan[10]);
if ( angka==12)
document.write(bulan[11]);
//-->
</script>
</body>
<html>
<head>
<title>Program Bulan</title>
</head>
<body>
<script language = "JavaScript">
<!--
var bulan = new Array();
angka = parseInt(prompt("Masukan Angka 1-12 =\n"));
bulan[0] = "Januari";
bulan[1] = "Februari";
bulan[2] = "Maret";
bulan[3] = "April";
bulan[4] = "Mei";
bulan[5] = "Juni";
bulan[6] = "Juli";
bulan[7] = "Agustus";
bulan[8] = "September";
bulan[9] = "Oktober";
bulan[10] = "November";
bulan[11] = "Desember";
if ( angka==1)
document.write(bulan[0]);
if ( angka==2)
document.write(bulan[1]);
if ( angka==3)
document.write(bulan[2]);
if ( angka==4)
document.write(bulan[3]);
if ( angka==5)
document.write(bulan[4]);
if ( angka==6)
document.write(bulan[5]);
if ( angka==7)
document.write(bulan[6]);
if ( angka==8)
document.write(bulan[7]);
if ( angka==9)
document.write(bulan[8]);
if ( angka==10)
document.write(bulan[9]);
if ( angka==11)
document.write(bulan[10]);
if ( angka==12)
document.write(bulan[11]);
//-->
</script>
</body>
<html>
Langganan:
Postingan (Atom)