Saturday, 9 January 2016

JAVASCRIPT : Prime-Number-Program

A prime number  is a natural number greater than 1 that has no positive divisors other than 1 and itself.

Continuing on the topic of interview questions for programming and software engineering type positions, I thought I’d brush up on a popular one.

Although I have never personally been asked about this, other people have told me that they’ve been asked to determine if a number is prime or to print out all prime numbers up to a certain number.

In most programming languages there is a modulus type function for determining the remainder of a division between two numbers. 

 We can certainly use this concept for determining if a number is prime because a modulus expression will return zero if the number isn’t prime.


JAVASCRIPT : Form-Input-Check

Form validation normally used to occur at the server, after the client had entered all the necessary data and then pressed the Submit button.
 If the data entered by a client was incorrect or was simply missing, the server would have to send all the data back to the client and request that the form be resubmitted with correct information. 
This was really a lengthy process which used to put a lot of burden on the server.
JavaScript provides a way to validate form's data on the client's computer before sending it to the web server. Form validation generally performs two functions.
First let us see how to do a basic form validation. In the above form, we are calling validate() to validate data when onsubmit event is occurring. The following code shows the implementation of this validate() function.


JAVASCRIPT : Working-With-the-Date-Function

Date and time values are used for many important functions such as searching, validation, and report generation. There is no standard format for dates in web applications, as people in different time zones and countries prefer different formats. 

Therefore, adapting to any kind of date format can be a challenge as a front end developer. Today, we are going to see how to effectively use date and time functions in JavaScript.

We can clearly see that the resulting date depends on your local time zone, as two different time zones are shown.

There is no single common format for dates, and we need to show date strings in different formats according to different situations. Basically, it is a two way process where we have to convert the string into a  object first and then convert it back to a string in the format we prefer. 

The initial process consists of converting the string provided by user input into a  object. Let’s consider some of the common user input methods for dates.


JAVASCRIPT : Print-Function

Many times you would like to place a button on your webpage to print the content of that web page via an actual printer. JavaScript helps you to implement this functionality using the print function of window object.
The JavaScript print function window.print prints the current web page when executed. You can call this function directly using the onclick event as shown in the following example.
Although it serves the purpose of getting a printout, it is not a recommended way. A printer friendly page is really just a page with text, no images, graphics, or advertising.
If you don’t find the above facilities on a web page, then you can use the browser's standard toolbar to get print the web page. Follow the link as follows.


JAVASCRIPT : Prompt-Example

JavaScript supports three important types of dialog boxes. 

These dialog boxes can be used to raise and alert, or to get confirmation on any input or to have a kind of input from the users.

 Here we will discuss each dialog box one by one.
An alert dialog box is mostly used to give a warning message to the users.

 For example, if one input field requires to enter some text but the user does not provide any input, then as a part of validation, you can use an alert box to give a warning message.

A confirmation dialog box is mostly used to take user's consent on any option. 


JAVASCRIPT : Confirmation-Example

He confirm method displays a dialog box with a specified message, along with an OK and a Cancel button.

A confirm box is often used if you want the user to verify or accept something.

The confirm box takes the focus away from the current window, and forces the browser to read the message.

 Do not overuse this method, as it prevents the user from accessing other parts of the page until the box is closed.



JavaScript arrays are used to store multiple values in a single variable.

The programs we have built so far have been seriously hampered by the fact that they were operating only on simple data types. 

This chapter will add a basic understanding of data structures to your toolkit. By the end of it, you’ll know enough to start writing some useful programs.

Numbers, Booleans, and strings are the bricks that data structures are built from. But you can’t make much of a house out of a single brick.