1 / 29

CONTOH LATIHAN JAVASCRIPT

CONTOH LATIHAN JAVASCRIPT. <html> <p><b> Program Fungsi </b></p><hr> <head> <script language ="JavaScript"> function nama() { alert ("Hallo nama saya …. "); } </script> </head> <body> <script language ="JavaScript"> nama(); </script> </body> </html>. CONTOH fungsi. <html>

brone
Download Presentation

CONTOH LATIHAN JAVASCRIPT

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CONTOH LATIHAN JAVASCRIPT

  2. <html> <p><b> Program Fungsi </b></p><hr> <head> <script language ="JavaScript"> function nama() { alert ("Hallo nama saya…."); } </script> </head> <body> <script language ="JavaScript"> nama(); </script> </body> </html> CONTOH fungsi

  3. <html> <head> <script language="JavaScript"> function pesan() { alert("Hallo sayaaktifdari even onload"); } </script> </head> <body onload ="pesan()"> </body> </html> fungsi

  4. <html> <head> <script language ="JavaScript"> function cetak(txt) { alert("Hallo " +txt) } function konfirmasi() { vartanya=confirm(“APAKAH INGIN MENAMBAH DATA LAGI ?"); if (tanya==true) { alert(“SILAHKAN ISI KEMBALI..!"); } else { alert(“TERIMA KASIH..!"); } } function masuk() { alert("Program iniberisicontoh\n"+ "membuatsuatukejadian\n\n"+ "SelamatBelajar ...!"); } Contoh fungsi

  5. function keluar() { alert("Terimakasihanda\n"+ "Telahmencoba program ini"); } </script> </head> <body onload="masuk()" onunload="keluar()"> <form> nama :<input type="text" name="nama" size=10> <input type="button" value="KIRIM" onclick="cetak(nama.value)"><hr> <a href="" onclick="konfirmasi(); return false;">KIRIM KE SISTEM</a> </form> </body> </html> sambungan

  6. <html> <head> <script language="JavaScript"> function inputpass() { varbaris=0; do { var pass = prompt("Masukkan Password",""); if(pass =="JOKER") { alert ("Selamat Password Benar"); break; } else { alert("Maaf Password Salah"); if(baris==3) { alert("Maafkesempatanandahanya 3 x"); } baris=baris+1; } } Contoh FUNGSI

  7. while(baris<3) } </script> </head> <body> <form> <input type="button" value="password" onclick="inputpass()"> </form> </body> </html> SAMBUNGAN

  8. <html> <head> <script language="JavaScript"> function inputpass(pass) { varbaris=0; do { // var pass = prompt("Masukkan Password",""); if(pass =="JOKER") { alert ("Selamat Password Benar"); break; } else { alert("Maaf Password Salah"); if(baris==3) { alert("Maafkesempatanandahanya 3 x"); } baris=baris+1; break; } } FUNGSI

  9. while(baris<3) } </script> </head> <body> <form> password : <input type="text" name="pass" size=10> <input type="button" value="KIRIM" onclick="inputpass(pass.value)"> </form> </body> </html> SAMBUNGAN

  10. <html> <head> <script language="JavaScript"> function cek() { var nim1 = document.fmform.nim.value; var nama1 = document.fmform.nama.value; var alamat1 = document.fmform.alamat.value; if(nim1=="") { alert("NIM harusdiisi ..!"); document.fmform.nim.focus(); return false; } FUNGSI

  11. else { if(nama1=="") { alert("NAMA harusdiisi ..!"); document.fmform.nama.focus(); return false; } else { if(alamat1=="") { alert("ALAMAT harusdiisi ..!"); document.fmform.alamat.focus(); return false; } else { alert("NIM :"+nim1+"\n"+ "Nama :"+nama1+"\n"+ "Alamat :"+alamat1); return true; } } } } SAMBUNGAN

  12. </script> </head> <body> <form name="fmform"> NIM :<input type="text" name="nim" size=10><br> Nama :<input type="text" name="nama" size=10><br> Alamat :<input type="text" name="alamat" size=10><hr> <input type="button" value="PROSES" onclick="cek()"> </form> </body> </html> SAMBUNGAN

  13. <html> <body> <script language ="JavaScript"> var a = 9 ; var b = 4 ; document.write ("Membandingkan 2 bilangan <hr>"); if (a > b) { document.write("bilangan = "+a+"lebihbesardari "+b); } if (a < b) { document.write("bilangan = "+b+"lebihkecildari "+a); } </script> </body> </html> KONDISI IF..

  14. <html> <body> <script language ="JavaScript"> var a = 9; selisih = 0; var b = 4; document.write ("bilangan a ="+a+"<br>"); document.write ("bilangan b ="+b+"<br>"); if (a>b) { selisih = a - b; document.write ("Bilangan = "+a+"lebihbesardari ="+b); document.write ("<br>Selisihnya ="+selisih); }else{ selisih = b - a ; document.write ("Bilangan = "+a+"lebihkecildari ="+b); document.write ("<br>Selisihnya ="+selisih); } </script> </body> </html> KONDISI IF....ELSE

  15. <html> <body> <script language ="JavaScript"> var a = -9; document.write ("bilangan ="+a+"<br>"); if (a>0) { document.write (a+"adalahbilangan POSITIP"); }else{ document.write (a+"adalahbilangan NEGATIP"); } </script> </body> </html> KONDISI IF..ELSE

  16. <html> <body> <script language ="JavaScript"> var a = 0; document.write ("bilangan ="+a+"<br>"); if (a>0) { document.write (a+"adalahbilangan POSITIP"); }else{ if (a<0) { document.write (a+"adalahbilangan NEGATIP"); } else { document.write ("Bilangan NOL"); } } </script> </body> </html> KONDISI IF...ELSE

  17. <html> <body> <script language ="JavaScript"> var nil = 55; document.write ("bilangan ="+nil+"<br>"); if (nil>=85) { document.write ("Grade A <br>"); document.write ("LULUS"); }else{ if (nil>=70 && nil<85) { document.write ("Grade B <br>"); document.write ("LULUS"); } else { if (nil>=60 && nil<70) { document.write ("Grade C <br>"); document.write ("LULUS"); } KONDISI IF...ELSE

  18. else { if (nil>40 && nil <60) { document.write ("Grade D <br>"); document.write ("GAGAL"); } else { document.write("GRADE E <br>"); document.write("GAGAL"); } } } } </script> </body> </html> SAMBUNGAN

  19. <html> <head> <script language ="JavaScript"> function cabang() { var a = parseFloat(document.fmform.bilangan1.value) ; var b = parseFloat(document.fmform.bilangan2.value) ; if(isNaN(a)) { a =0.0; } if(isNaN(b)) { b =0.0; } if (a > b) { alert("bilangan = "+a+"lebihbesardari "+b); } if (a < b) { alert("bilangan = "+a+"lebihkecildari "+b); } } KONDISI IF

  20. </script> </head> <body> <form name ="fmform"> Bilangan 1 : <input type ="text" name="bilangan1" size=5><br> Bilangan 2 : <input type ="text" name="bilangan2" size=5><hr> <input type ="button" value="Bandingkan" onClick ="cabang()"> </form> </body> </html> SAMBUNGAN

  21. <html> <body> <b> cetakangka 0 - 9 dengan do..while </b><hr> <script language = "JavaScript"> var x = 0; do { document.write(x+"<br>"); x++; } while (x <= 9) </script> </body> </html> DO...WHILE

  22. <html> <body> <b> cetakangka 0 - 9 dengan while </b><hr> <script language = "JavaScript"> var x = 0; while (x <= 9) { document.write(x+"<br>"); x++; } </script> </body> </html> WHILE

  23. <html> <body> <script language ="JavaScript"> vartanya = true while(tanya==true) { varangka = prompt("MasukkanAngka :",""); for(x=1;x<=angka;x++) { for(j=1;j<=x;j++) { document.write("*"); } document.write("<br>"); } document.write("<hr>PiramidaBintang ="+angka+"<br>"); vartanya = confirm("Apakahakanlanjut ?") if (tanya==true) {continue;} else {break;} } </script> </body> </html> GABUNGAN WHILE, FOR DAN IF

  24. <html> <body> <script language ="JavaScript"> vartanya = true ; var h=0; var c=0; while(tanya==true) { varangka = prompt("MasukkanAngka :",""); for(x=1;x<=angka;x++) { h=c+x; for(j=1;j<=h;j++) { document.write(" * "); } document.write("<br>"); c=c+1; } CONTOH 2

  25. document.write("<hr>PiramidaBintang ="+angka+"<br>"); vartanya = confirm("Apakahakanlanjut ?") if (tanya==true) {continue;} else {break;} } </script> </body> </html> SAMBUNGAN

  26. <html> <body> <script language ="JavaScript"> document.write("<b> Cetakangka 1 - 9 </b><hr>"); for (X=1 ; X<=9 ; X+=2) { document.write(X+" | "); } </script> </body> </html> FOR

  27. <html> <body> <script language ="JavaScript"> document.write("<b> Cetakangka 1 - 9 </b><hr>"); vargenap=0; vartgenap=0; varganjil=0; vartganjil=0; var total=0; for (X=1 ; X<=10 ; X++) { document.write(X+" | "); if((X%2)==0) { genap=genap+1; tgenap=tgenap+X; } FOR

  28. else { ganjil =ganjil+1; tganjil=tganjil+X; } total = total+X; } document.write("<br>Total Bilangan="+total+"<br>\n"+ "ganjilada="+ganjil+"totalnyaada ="+tganjil+"<br>\n"+ "genapada ="+genap+"totalnyaada="+tgenap); </script> </body> </html> SAMBUNGAN

More Related