Contoh-contoh penulisan JavaScript

Penulisan code JavaScript bisa dilakukan didalam tag body html,head tag html dan external file yaitu dalah satu file terpisah berikut contoh-contoh cara penulisan code javascript :

1. Contoh penulisan code javascript dalam tag body HTML

<!DOCTYPE html>
<html>
<body>
<script type=text/javascript>
document.writer(“Belajar javascript”)
</body>
</html>

Output

Belajar javascript

2. Contoh penulisan code javascript external file
Buat file JavasScript message.js

function msg(){
alert("Hello Javatpoint");
}

Buat code html hello.html

<!DOCTYPE html>
<html>
<body>
<script type="text" src="message.js" ><javascript>
<input type="button" value="click" onclick="msg()">
</body>
</html>

masukan atau panggil file message.js

hyvercode

Leave a Reply

Your email address will not be published. Required fields are marked *