Contoh latihan javascript
Download
1 / 29

CONTOH LATIHAN JAVASCRIPT - PowerPoint PPT Presentation


  • 79 Views
  • Uploaded on

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>

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about ' CONTOH LATIHAN JAVASCRIPT' - brone


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.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

Contoh fungsi

<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


Fungsi

<html>

<head>

<script language="JavaScript">

function pesan()

{

alert("Hallo sayaaktifdari even onload");

}

</script>

</head>

<body onload ="pesan()">

</body>

</html>

fungsi


Contoh fungsi1

<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


Sambungan

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


Contoh fungsi2

<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


Sambungan1

while(baris<3)

}

</script>

</head>

<body>

<form>

<input type="button" value="password" onclick="inputpass()">

</form>

</body>

</html>

SAMBUNGAN


Fungsi1

<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


Sambungan2

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


Fungsi2

<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


Sambungan3

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


Sambungan4

</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


Kondisi if

<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..


Kondisi if else

<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


Kondisi if else1

<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


Kondisi if else2

<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


Kondisi if else3

<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


Sambungan5

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


Kondisi if1

<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


Sambungan6

</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


Do while

<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


While

<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


Gabungan while for dan if

<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


Contoh 2

<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


Sambungan7

document.write("<hr>PiramidaBintang ="+angka+"<br>");

vartanya = confirm("Apakahakanlanjut ?")

if (tanya==true)

{continue;}

else

{break;}

}

</script>

</body>

</html>

SAMBUNGAN


<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


<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


Sambungan8

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


ad