Perintah IF


 

 

 

 

 

 

 

Perintah if adalah perintah untuk membandingkan 2 buah data atau lebih. Untuk memperbandingkan data digunakan operator logika. Lihat kembali Operator Arithmatika dan Operator Logika yang terdapat pada postingan sebelumnya, sebab perintah if tidak bisa lepas dari operator ini..
Sintak :

If ( lakukan perbandingan disini )
{
………………………..
Blok ini akan dikerjakan jika perbandingan dipenuhi.
………………………..
}
Else
{
Blok ini akan dikerjakan jika perbandingan tidak dipenuhi.
………………………….
}

CONTOH PROGRAM
Berikut ini adalah contoh program untuk memperbandingkan 2 buah keadaan, jika umur pengguna 17 tahun kebawah, maka program akan tampil peringatan “ Maaf Anda Belum Bisa Masuk” , dan jika pengguna 17 tahun ke atas, maka program akan menampilkan “ Anda Boleh Masuk”.

<html>
<head>
<title>Contoh Fungsi if</title>
</head>
<body>
<script language=”javascript”>
var nama= prompt(“Ketik Nama Anda : “)
var umur= prompt(“Berapa Usia Anda ?”)
document.write(“Nama Anda :”+nama+”<br>”)
if(umur>=17)
{
document.write(“Usia Anda =”+umur+”tahun<br>”)
document.write(“<h3>Anda Boleh Masuk!!</h3>”)
}
else
{
document.write(“Usia Anda baru :”+umur+”tahun<br>”)
document.write(“<h3>Maaf Anda Belum Bisa Masuk!!!!!!!!</h3>”)
}
</script>
</body>
</html>

HASIL SETELAH PROGRAM DIJALANKAN..
Program akan meminta Nama Pengguna dibawah ini :

Setelah di Klik OK, maka akan muncul kembali program meminta umur pengguna :

Jika Usia lebih dari 17 ( seperti contoh penulis ) maka hasilnya akan tampak seperti gambar dibawah :

Jika Usia kurang dari 17 maka hasilnya akan tampak seperti gambar dibawah :

DOWNLOAD FILE LENGKAP
Password : http://www.ilmudesain.web.id

  1. My developer is trying to convince me to move to .net from
    PHP. I have always disliked the idea because of the costs.
    But he’s tryiong none the less. I’ve been using WordPress on several
    websites for about a year and am worried about switching to another
    platform. I have heard fantastic things about blogengine.net.
    Is there a way I can import all my wordpress content into it?

    Any kind of help would be greatly appreciated!|

  2. I blog frequently and I really appreciate your information.
    This great article has really peaked my interest.
    I am going to bookmark your blog and keep checking for new
    details about once a week. I opted in for your Feed too.|

  3. I’ve been exploring for a little for any high quality articles
    or weblog posts on this sort of area . Exploring in Yahoo I at last stumbled upon this site.
    Studying this info So i’m glad to express that I’ve an incredibly good uncanny feeling I discovered just what I needed.

    I such a lot definitely will make certain to do not forget this
    website and give it a glance on a constant basis.|

  4. whoah this blog is wonderful i like reading your posts. Keep up the good work!
    You already know, many persons are looking around for this info,
    you could aid them greatly. |

  5. Hey there! Quick question that’s totally off topic.
    Do you know how to make your site mobile friendly? My weblog looks weird
    when browsing from my iphone. I’m trying to find a theme
    or plugin that might be able to fix this issue. If you have any recommendations, please share.

    Appreciate it!|

  6. I seriously love your website.. Very nice colors & theme. Did you create this website yourself?
    Please reply back as I’m trying to create my
    own personal site and want to find out where you got this from or exactly what the theme is named.

    Cheers!|

  7. I read this piece of writing completely about the
    resemblance of most up-to-date and previous technologies, it’s remarkable article.|

  8. I blog often and I truly thank you for your information.
    Your article has really peaked my interest. I will bookmark your website and keep checking for new information
    about once per week. I opted in for your Feed as well.|

  9. What i do not realize is in truth how you are now not
    really much more neatly-favored than you may be now.
    You’re so intelligent. You already know therefore significantly on the subject of this subject, made me for
    my part imagine it from a lot of various angles. Its
    like men and women don’t seem to be interested unless it’s something
    to do with Girl gaga! Your individual stuffs outstanding.
    All the time care for it up!|

  10. With havin so much content do you ever run into any issues of plagorism or copyright
    violation? My website has a lot of exclusive content I’ve
    either written myself or outsourced but it seems a lot of it is popping it up all over the internet without my agreement.
    Do you know any methods to help prevent content from being ripped off?
    I’d definitely appreciate it.|

  11. My spouse and I stumbled over here from a different web page
    and thought I might as well check things out. I like what I see so now i’m following you.
    Look forward to looking over your web page repeatedly.|

  12. Whats up very nice website!! Guy .. Excellent .. Wonderful ..
    I’ll bookmark your site and take the feeds also?
    I’m glad to search out so many useful info here within the publish,
    we want work out extra strategies on this regard, thanks for sharing.
    . . . . .|

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: