First JavaScript Code

Build your first program

Let's see the power of JavaScript through a program.

Step 1:

Go to JSbin.com.

Step 2:

Copy this into the HTML portion

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<h1>Do you copy?</h1>
</body>
</html>

Step 3:

Copy this into the JavaScript portion

document.querySelector('h1').addEventListener('copy', function() {
document.body.style.background="teal";
});

Step 4:

Copy the text that says "Do you copy?" from the Output section.

What happens?!