Senin, 27 November 2017

Program Mengetahui Zodiak dan Shio Menggunakan Javascript

TUGAS UAS
Program Mengetahui Zodiak dan Shio Menggunakan Javascript

Nama : Khanif Maulana
Nim : 1117101511
 Assalamualikum Wr Wb
Program dengan inpukan nama, tanggal lahir, bulan dan tahun lahir.

script

<!Doctype html>
<html>
 <head>
  <title>Program untuk mengetahui Zodiak dan Shio</title>
  <script language="javascript">

   function cek()
   {
   //variabel
   var start = 1901,
   birthyear = document.
   zodiac.year.value,
   date=document.zodiac.date.value,
   month=document.zodiac.month.selectedIndex;
//proses
   with (document.zodiac.sign){
/* if di bawah ini bergandengan dengan "atau|| "dikarenakan zodiak menggunakan bulan yang berbeda-beda
jadi jika di baca bulan sama dengan 1 dan date lebih dari 20 atau bulan sama dengan 2 dan tanggal kurang dari 18 maka
value yang muncul adalah aquarius
*/
   if (month == 1 && date >=20 || month == 2 && date <=18)  {value = "Aquarius";}
   if (month == 1 && date > 31) {value = "tanggal tidak valid";}
   if (month == 2 && date >=19 || month == 3 && date <=20) {value = "Pisces";}
   if (month == 2 && date > 29) {value = "tanggal tidak valid";}
   if (month == 3 && date >=21 || month == 4 && date <=19) {value = "Aries";}
   if (month == 3 && date > 31) {value = "tanggal tidak valid";}
   if (month == 4 && date >=20 || month == 5 && date <=20) {value = "Taurus";}
   if (month == 4 && date > 30) {value = "tanggal tidak valid";}
   if (month == 5 && date >=21 || month == 6 && date <=21) {value = "Gemini";}
   if (month == 5 && date > 31) {value = "tanggal tidak valid";}
   if (month == 6 && date >=22 || month == 7 && date <=22) {value = "Cancer";}
   if (month == 6 && date > 30) {value = "tanggal tidak valid";}
   if (month == 7 && date >=23 || month == 8 && date <=22) {value = "Leo";}
   if (month == 7 && date > 31) {value = "tanggal tidak valid";}
   if (month == 8 && date >=23 || month == 9 && date <=22) {value = "Virgo";}
   if (month == 8 && date > 31) {value = "tanggal tidak valid";}
   if (month == 9 && date >=23 || month == 10 && date <=22) {value = "Libra";}
   if (month == 9 && date > 30) {value = "tanggal tidak valid";}
   if (month == 10 && date >=23 || month == 11 && date <=21) {value = "Scorpio";}
   if (month == 10 && date > 31) {value = "tanggal tidak valid";}
   if (month == 11 && date >=22 || month == 12 && date <=21) {value = "Sagittarius";}
   if (month == 11 && date > 30) {value = "tanggal tidak valid";}
   if (month == 12 && date >=22 || month == 1 && date <=19) {value = "Capricorn";}
   if (month == 12 && date > 31) {value = "tanggal tidak valid";}
   }
/* Untuk menentukan shio, caranya dengan mendapatkan sisa bagi tahun dengan 12 (karena shio akan berulang setiap 12 tahun sekali)
sebenarnya, cara ini tidak terlalu akurat mengingat pergantian tahun dalam penanggalan Cina tidak tepat seperti pergantian tahun masehi
*/
   x = (start - birthyear) % 12
   with (document.zodiac.csign){

   if (x == 1 || x == -11) {value = "Tikus";}
   if (x == 0) {value = "Kerbau";}
   if (x == 11 || x == -1) {value = "Macan";}
   if (x == 10 || x == -2) {value = "Kelinci";}
   if (x == 9 || x == -3) {value = "Naga";}
   if (x == 8 || x == -4) {value = "Ular";}
   if (x == 7 || x == -5) {value = "Kuda";}
   if (x == 6 || x == -6) {value = "Kambing";}
   if (x == 5 || x == -7) {value = "Monyet";}
   if (x == 4 || x == -8) {value = "Ayam";}
   if (x == 3 || x == -9) {value = "Anjing";}
   if (x == 2 || x == -10) {value = "Babi";}
   }
   }
   </script>
   </head>
   <body>
   <body bgcolor="pink">
    <form name="zodiac">
<h1 align="center"><font color="orange" face="arial" >Cek Zodiak dan Shio</h1>
                <table border="1" cellpadding="2" cellspacing="1" align="center" width="30%">
                    <tr>
      <div align="center">
  <td><b><i>Nama</i></b></td>
  <td><div align="left">
  <input type="text" size="20" name="Nama" value="masukkan nama" onClick=value="">
  </td></div>
 
       <tr>
        <td><b><i>Tahun Lahir</i></b></td>
        <td><div align="left">
        <input type="text" size="10" name="year" value="Input Tahun" onClick=value=""></div>
        </td>
       </tr>
       <tr>
<td><b><i>Bulan Lahir</i></b></td>
        <td><div align="left">
        <select name="month">
        <option value="x">Pilih Bulan Lahir</option>
        <option value="1">Januari</option>
        <option value="2">Februari</option>
        <option value="3">Maret</option>
<option value="4">April</option>
        <option value="5">Mei</option>
        <option value="6">Juni</option>
        <option value="7">Juli</option>
        <option value="8">Agustus</option>
        <option value="9">September</option>
<option value="10">Oktober</option>
        <option value="11">November</option>
        <option value="12">Desember</option></select>
        </div></td>
       </tr>
       <tr>
        <td><b><i>Tanggal</i></b></td>
<td><div align="left"><input type="text" name="date" value="Tanggal Lahir" size="3" onClick=value=""></div></td>
       </tr>
       <tr>
        <td><b><i>Zodiak</i></b></td>
        <td><div align="left"><input type="text" name="sign" size="16" value="" align="right"></div></td>
       </tr>
       <tr>
        <td><b><i>Shio</i></b></td>
<td><div align="left"><input type="text" name="csign" size="12"></div></td>
       </tr>
       <tr>
        <td align="center" colspan="2">
        <input type="button" value="Cek !" onClick="cek()">
<input type="reset" value="Ulang !">
        </td>
       </tr>
    </table>
   </form>
         

 <h3 align="center"><font color="blue" face="Snap ITC" size="6">Oleh khanif maulana</font></h3>
  <br><font ><marquee direction="left" style="background:black">Algoritma Pemrograman || Tugas Uts || Oleh Khanif Maulana||1117101511||</marquee></font>


</body>
 </html>


hasil dari script diatas adalah :


contoh inputkan  nama Loli, tahun lahir 1999, bulan lahir : april tanggal lahir 30.





dari hasil tersebut outputnya
zodiak Taurus dan Bershio Kelinci

gambar diatas adalah hasilnya..semoga bermanfaat.

Wassalamualaikum Wr Wb

1 komentar: