The Basics of Javascript

The Basics of Javascript

Javascript, often referred to as the language of the Web. Almost all web browsers can run Javascrip thus, making it one of the most popular programming languages in the world. Though, it has a low barrier to entry, all you need is a text editor and a web browser to write your programs.

Once you have garnered an in-depth understanding of JavaScript, you will find it is a flexible and expressive language that can create some powerful applications.

JavaScript is a high-level language that is compiled at run time. This means that it requires an engine that is responsible for interpreting programs and running them. Firefox, Chrome, or Internet Explorer are few browsers where JavaScript engines are found, although JavaScript can be run without a browser.

JavaScript is also a dynamic language, which means that elements of a program can change while it is running.

Lets program!!!

Open your text editor (Notepad++, or Netbeans, etc) and enter the following code:

<head>
<meta charset=”utf-8″>
<title>I can change background</title>
</head>
<button id=”button”>Click me to change background</button>
<script src=”js/change-background.js”></script>
</body>
</html>

Save as change-background.html

Create a new file name, change-background.js  and enter the following code:

var button =  document.getElementById(“button”);

var changebackground = [“yellow”, “red”, “orange”, “green”, “blue”, “black”, “white”];

function change(){
document.body.style.background = changebackground[Math.floor(7*Math.random())];
}
button.addEventListener(“click”, change);

Demo:

http://mailconcept.net/demos/working-js/change-background.html

Feel free to comment or send me an email if you have any project that you need help with at inf@mailconcept.net

Leave a Reply

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