IT Java Script
{Author Name [first-name middle-name-initials last-name]}
{Institution Affiliation [name of Author’s institute]}
There are five components or concepts of code that are most elementary or important for any programming language of technology. The five components are:
Variables
Data Structures
Control Structures
Tools
Variables: Variables can be considered the most basic building block or component for any programming language construct. Variable hold information, references and are both storage location and a symbolic name holding data that relevant to a proper execution of the code. For example in the attached Javascript code that prints relevant information for Operating System upgrade, there are multiple variables used that hold information like current date, initial upgrade date, group date and time left for the upgrade. The variables play significant role in forming the structure of the code and managing its flow (Page, 2012).
Syntax: Syntax is the set of rules that defines the placement and proper use of programming language symbols. For example curly braces and round brackets are symbols that must be used in a proper format and at proper places. In the Javascript program for upgrade information both of these symbols are used properly to denote methods and code blocks respectively (Page, 2012).
Data Structures: Data structures is a format or process for storing data inside the memory of a running program. Some examples of data structures available in most programming languages are Lists, HashMaps, Maps and Arrays. Data structures not only provides efficient means of storing data but also an effective way of reducing programming lines of code (Page, 2012).
Control Structure: A control structure is a way of controlling the flow of code, taking certain decisions based on input data and altering the code path for scenario based use-cases. A control structure is based upon the premise of the analysis of data stored inside the variable being analyzed and then altering the program’s output. For example, in the Javascript program, based upon group name variable and its stored value the output message is changing (Page, 2012).
Tools: Tools can be of two types for any programming language, it can be internal API (Application Programming Interface) with programming templates and code for common program functions, for example mathematical programs. The other types of tools are IDEs (Integrated Development Environments) that facilitate the creation and testing of programming code for example Eclipse and Netbeans IDE for Java programming and Visual Studio .NET for VB.NET programming. There are various online tools and IDEs available like the one from TutorialsPoint.com (http://www.tutorialspoint.com/try_javascript_online.php) for Javascript programming and testing.
Javascript Assignment
The following changes have been done in the Javascript code for printing proper message to different groups of users.
Take out the initial upgrade date into a separate variable named initialUpgradeDate.
Create a control structure based on group information provided, i.e. different message for different groups but not repeating the common code.
Creating a separate Javascript method i.e. printMessage() that gets called at onload event of the HTML body
For each group the group value will be different i.e. 1, 2, 3, 4 or 5. The group value is passed under variable group in the printMessage(group) method.
The updated code is below.
Index.html (base file)
<!DOCTYPE html>
<html>
<head>
<script src="script.js"></script>
</head>
<body onload="javascript:printMessage(1);">
</body>
</html>
script.js (Javascript file)
function printMessage(group)
{
var groupName = "Group 1";
var initialUpgradeDate = "July 6, 2016";
var today = new Date();
var UpgradeDay = new Date(initialUpgradeDate);
if(group==2)
{
UpgradeDay.setDate(UpgradeDay.getDate() + 2);
groupName = "Group 2";
}
if(group==3)
{
UpgradeDay.setDate(UpgradeDay.getDate() + 5);
groupName = "Group 3";
}
if(group==4)
{
UpgradeDay.setDate(UpgradeDay.getDate() + 8);
groupName = "Group 4";
}
if(group==5)
{
UpgradeDay.setDate(UpgradeDay.getDate() + 10);
groupName = "Group 5";
}
var msPerDay = 24 * 60 * 60 * 1000 ;
var timeLeft = (UpgradeDay.getTime() - today.getTime());
var days = timeLeft / msPerDay;
var daysLeft = Math.floor(days);
document.write("<B><U>"+groupName+"</U></B><BR><BR>There are only<BR> <H4>" + daysLeft + " days </H4> Until Your Computer Upgrade<P>");
}
Screens (http://www.tutorialspoint.com/try_javascript_online.php)
First Group: Group Value 1
Second Group: Group Value 2 (Change input value inside Index.html)
Third Group: Group Value 3 (Change input value inside Index.html)
Fourth Group: Group Value 4 (Change input value inside Index.html)
Fifth Group: Group Value 5 (Change input value inside Index.html)
References
Page, T. (2012). The 5 Basic Concepts of any Programming Language. How to Program with
Java. Retrieved 4 June 2016, from https://howtoprogramwithjava.com
/the-5-basic-concepts-of-any-programming-language-concept-4/