Monday, June 4, 2012

Javascript

1. What is Java script?
It is a prototype-based scripting language that is dynamic, weakly typed and has first-class functions. It is a multi-paradigm language, supporting object-oriented, imperative, and functional programming styles. JavaScript is typically used to manipulate existing HTML elements. 

2.What is Object Oriented Programming (OOP)?
It is a programming paradigm using "objects" – data structures consisting of data fields and methods together with their interactions – to design applications and computer programs.

3.What three components make up OOP?
  • Encapsulation
    Encapsulation is the hiding of data implementation by restricting access to accessors and mutators.
    Accessor

    An accessor is a method that is used to ask an object about itself. In OOP, these are usually in the form of properties, which have, under normal conditions, a get method, which is an accessor method. However, accessor methods are not restricted to properties and can be any public method that gives information about the state of the object.
  • Mutator Mutators are public methods that are used to modify the state of an object, while hiding the implementation of exactly how the data gets modified. Mutators are commonly another portion of the property discussed above, except this time its the set method that lets the caller modify the member data behind the scenes. 
  • Inheritance
    Inheritance is a way to reuse code of existing objects, or to establish a subtype from an existing object, or both, depending upon programming language support. In classical inheritance where objects are defined by classes, classes can inherit attributes and behavior from pre-existing classes called base classes, superclasses, parent classes or ancestor classes. The resulting classes are known as derived classes, subclasses or child classes. The relationships of classes through inheritance gives rise to a hierarchy. In prototype-based programming, objects can be defined directly from other objects without the need to define any classes, in which case this feature is called differential inheritance.


4. Give an example of an object, a method and an event.
Object: Date
Method: (Set the day of the month)


var d = new Date();
d.setDate(15);


Event: (Display the date when button is clicked)

<!DOCTYPE html>
<html>

<head>
<script type="text/javascript">
function displayDate()
{
document.getElementById("demo").innerHTML=Date();
}
</script>
</head>

<body>

<h1>My First Web Page</h1>

<p id="demo"></p>

<button type="button" onclick="displayDate()">Display Date</button>

</body>
</html>


5. Where is Java script placed in a html page?
JavaScript code can be inserted either in the head of the document (between the <head> and </head> tags) or in the body (between the <body> and </body>tags). However, it is a good idea to always place JavaScript code in the head if you can.


6. What four lines of code indicate the beginning and end of java script?


7. What do javascript forms do? Name two objects that could be included in a form.
Javascript forms work like any other forms do; gathering data into a single page. Form validation work to check if things like has the user left required fields empty, entered a valid e-mail address, has the user entered a valid date and has the user entered text in a numeric field? Names and addressed of people could be included in a form. 


8. What four attributes does a java script button have?
The JavaScript button effects are created using images. The JavaScript button requires three images for the different stages (normal, active and clicked). When the user moves the mouse over the image, the image is switched to the ‘active’ image. When the user clicks the image, the image is switched to ‘clicked’ image.
You can give the URL in the ‘href’ attribute of the anchor (<a>) tag to navigate to that page when the user clicks the button.

Alter a basic HTML page to contain the code used in chapter 1 of this tutorial as well as display a clock as coded by the java script in the link below.

2 comments:

  1. Nicely set out blog - I like the use of tabs, you could have your posts categorised in the tabs. Some very detailed posts. Many of the tasks are not "answered", ie. you have posted the questions only. Just needed to see some more tasks posted on your blog.


    14/20

    ReplyDelete
    Replies
    1. Thank you sir! I haven't organized my posts by tabs because I don't want to duplicate them but at the bottom of this page there is an archive which sorts out my posts by date. I have gone over the unfinished posts and completed most of them.

      Delete