Selasa, 23 Desember 2014

Script kuis sederhana untuk Website anda

Sekarang kita akan membuat kuis matematika sederhana yang nantinya akan ditaruh dalam website anda seperti dibawah ini :

Untitled Document
1. 3 + 7 =
2. 1 2 = 2
3. * 10 = 2000
4. 14 / = 2
5. 4 * 5 =







pertama copy script ini ke dalam code HTML anda :
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script language="javascript">
function proses()
{
    s1 = (document.form1.satu.value);
    s2 = (document.form1.dua.value);
    s3 = (document.form1.tiga.value);
    s4 = (document.form1.empat.value);
    s5 = (document.form1.lima.value);
    hasilakhir = "";
if (document.form1.satu.value!="")
    {
     if (document.form1.satu.value=="10")
         {
        s1 = "Benar";
        hasilakhir = hasilakhir + "1."+ s1 + "<br/>";
         }
     else
        {
            s1 = "Salah";
        hasilakhir = hasilakhir + "1."+ s1 + "<br/>";
        }
    }
   
if (document.form1.dua.value!="")
    {       
    if (document.form1.dua.value=="*")
         {
        s2 = "Benar";
        hasilakhir = hasilakhir + "2."+ s2 + "<br/>";
        }
     else
        {
            s2 = "Salah";
        hasilakhir = hasilakhir + "2."+ s2 + "<br/>";
        }
   
    }
   
if (document.form1.tiga.value!="")
    {       
    if (document.form1.tiga.value=="200")
         {
        s3 = "Benar";
        hasilakhir = hasilakhir + "3."+ s3 + "<br/>";
        }
     else
        {
            s3 = "Salah";
        hasilakhir = hasilakhir + "3."+ s3 + "<br/>";
        }
   
    }
if (document.form1.empat.value!="")
    {       
    if (document.form1.empat.value=="7")
        {
        s4 = "Benar";
        hasilakhir = hasilakhir + "4."+ s4 + "<br/>";
         }
     else
        {
            s4 = "Salah";
        hasilakhir = hasilakhir + "4."+ s4 + "<br/>";
        }
   
    }
if (document.form1.lima.value!="")
    {       
    if (document.form1.lima.value=="20")
        {
        s5 = "Benar";
        hasilakhir = hasilakhir + "5."+ s5 + "<br/>";
         }
     else
        {
            s5 = "Salah";
        hasilakhir = hasilakhir + "5."+ s5 + "<br/>";
        }
   
    }

    document.getElementById("hasil").innerHTML = hasilakhir;
}


</script>




</head>

<body>
</body>
</html>
<form id="form1" name="form1" method="post" action="">
1. 3 + 7 =
  <label>
  <input type="text" name="satu" id="satu" />
  </label>
  <br />
  2. 1
  <label>
  <input type="text" name="dua" id="dua" />
  </label>
   2 = 2<br />
   3.
   <label>
   <input type="text" name="tiga" id="tiga" />
   </label>
    * 10 = 2000<br />
    4. 14 /
    <label>
    <input type="text" name="empat" id="empat" />
    </label>
    = 2<br />
    5. 4 * 5 =
    <label>
    <input type="text" name="lima" id="lima" />
    </label>
    <p>
      <label>
      <input type="button" name="Button" id="Button" value="proses" onclick="proses()" />
      </label>
    </p>
    <p><br />
    </p>
   
<div id="hasil">
</div>
</form>

kemudian simpan dengan extency ***.html (simbol *** diganti dengan file yang anda inginkan)

Tidak ada komentar:

Posting Komentar