Your SlideShare is downloading. ×
Pertemuan 09
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Saving this for later?

Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime - even offline.

Text the download link to your phone

Standard text messaging rates apply

Pertemuan 09

29
views

Published on


0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
29
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
1
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Agenda • Mengambil nilai dari prompt() • Konversi string ke bilangan dengan parseInt(), parseFloat() dan eval(). • Comments
  • 2. Mengambil nilai dari prompt() • Nilai suatu variabel dapat diberikan lewat kotak dialog. • Kotak dialog input dimunculkan dengan bentuk: Prompt(“Pesan”,”nilai devalut”)
  • 3. Contoh: <html> <head><title>Prompt</title></head> <body> <SCRIPT LANGUANGE="JavaSript"> var nama = prompt("Input Nama",""); var alamat = prompt("Input Alamat",""); var jkel = prompt("Input Jemis Kelamin",""); document.write("<font size=5>"); document.write("<u>Data yang telah dimasukkan</u></font>"); document.write("<font size=4 color=blue>"); document.write("<br>Nama :"+nama); document.write("<br>Alamat :"+alamat); document.write("<br>Jenis Kelamin :"+jkel); </SCRIPT> </body></html>
  • 4. Hasil:
  • 5. Hasil
  • 6. Konversi String ke Bilangan • parseInt() : untuk mengkonversi string ke bilangan integer • parseFloat() : untuk mengkonversi string ke bilangan real (desimal) •eval() : untuk mengkonversi string desimal dan interger ke bentuk bilangan
  • 7. Contoh: Tanpa Konversi <html> <head><title>Prompt</title></head> <body> <SCRIPT LANGUANGE="JavaSript"> var a = prompt("Input Nilai a",""); var b = prompt("Input Nilai b",""); document.write("<font size=5>"); document.write("<u>Operasi Aritmatika</u></font>");
  • 8. document.write("<font size=4 color=blue>"); document.write("<br>a = "+a); document.write("<br>b = "+b); document.write("<br>"+a+" + "+b+" = "+a+b) document.write("<br>"+a+" x "+b+" = "+a*b) </SCRIPT> </body></html>
  • 9. Hasil:
  • 10. Hasil2 Hasilnya Tidak sesuai
  • 11. Contoh: Dengan Konversi <html> <head><title>Prompt</title></head> <body> <SCRIPT LANGUANGE="JavaSript"> var a = parseInt(prompt("Input Nilai a","")); var b = parseInt(prompt("Input Nilai b","")); document.write("<font size=5>"); document.write("<u>Operasi Aritmatika</u></font>");
  • 12. document.write("<font size=4 color=blue>"); document.write("<br>a = "+a); document.write("<br>b = "+b); document.write("<br>"+a+" + "+b+" = "+(a+b)) document.write("<br>"+a+" x "+b+" = "+a*b) </SCRIPT> </body> </html>
  • 13. Hasil
  • 14. Contoh Lain: <HTML><HEAD><TITLE>Konversi Bilangan</TITLE> <BODY> <SCRIPT LANGUANGE="JavaSript"> var x = "3"; var y = "5.5"; var z = "3 + 5.5"; document.write("<font size=5>"); document.write("<u>Konversi Bilangan</u></font>"); document.write("<font size=4 color=blue><br>");
  • 15. document.write(' x = "'+x+'"'); document.write('; y = "'+y+'"'); document.write('; z = "'+z+'"'); document.write("<br>Hasil parseInt(): ") document.write(" x = "+parseInt(x)) document.write("; y = "+parseInt(y)) document.write("; z = "+parseInt(z)) document.write("<br>Hasil parseFloat(): ") document.write(" x = "+parseFloat(x))
  • 16. document.write("; y = "+parseFloat(y)) document.write("; z = "+parseFloat(z)) document.write("<br>Hasil eval(): ") document.write(" x = "+eval(x)) document.write("; y = "+eval(y)) document.write("; z = "+eval(z)) </SCRIPT> </BODY> </HTML>
  • 17. Hasil: Hasil Tidak Sesuai
  • 18. Baris Komentar • Baris komentar pada JavaSript menggunakan tanda // • Tanda // sebagai baris komentar dapat ditempatkan pada baris tersendiri atau ditempatkan pada
  • 19. Contoh: <html> <head><title>Baris Komentar</title></head> <body> <SCRIPT LANGUANGE="JavaSript"> var l = 15; // Variabel Lebar var p = 20; // Variabel Panjang var a = l * p; // Hitung Luas // Menampilkan Hasil document.write("<font size=5>");
  • 20. // cetak judul document.write("<u>Hitung Luas Segi Empat</u></font>"); document.write("<font size=4 color=blue><br>"); // cetak data dan hasil document.write('<br>Lebar = '+l); document.write('<br>Panjang = '+p); document.write('<br>Luas = '+a); </SCRIPT> </body> </html>
  • 21. Hasil: