11/5/2012
Reading time: 6 mins
Reading time: 6 mins
Beginners guide to programming in javascript for non programmers
The main objective of this guide is to introduce you with the programming with the least applications. All you need is a browser, Chrome/Firefox or IE and a text editor notepad.
Who is this tutorial for?
- A non programmer / Beginner level programmer with HTML knowledge
What will this guide teach?
- To create a simple application that will plan weekend by summing two guests' money
Technical objectives
- Initializing and assigning variables
- Taking user input
- Outputting the response to the user
- arithmatic operations (Addition)
- Conditional statement if .. else …
<!DOCTYPE html>
<html>
<head>
<title>Javascript Programming</title>
<script>
//initializing variables
var interviewer,name1,name2;
var money1=0,money2=0,totalmoney=0;
//Ask names from the user
interviewer = "Anil";
name1 = prompt("what is your name guest 1?");
name2 = prompt("what is your name guest 2?");
//greetings
alert("Hello " + name1 + " and "+name2+"!!!!!!!!!!!");
alert("I am " + interviewer);
//ask how much money they have
money1 = parseInt(prompt("How much money do you have "+name1+"?"));
money2 = parseInt(prompt("How much money do you have "+name2+"?"));
//add money
totalmoney = money1 + money2;
//tell them how much money they have
alert("Combining both of you, you have $"+totalmoney);
if(totalmoney > 1000){
alert("Lets go for shoppiiiinnnngggg!!!!")
}
else if(totalmoney>500){
alert("Lets Go for movies!! We can get some popcorn and cold drinks too!!")
}
else if(totalmoney>100){
alert("Lets go to cafe! have some coffee with pastries!!!")
}
else{
alert("Boil some eggs and noodles.. We are going to Enjoy at home!!")
}
</script>
</head>
<body>
<h1>Javascript Programming</h1>
</body>
</html>