Unit 5 Read Me
Unit 5 Read Me
Snap recap
1. List the elements of HTML you have learnt so far
2. What do you think id s limitation of HTML script?
Learning objective
Introduction
HTML is a very limited document formatting language. It is based on tags that instruct the
browser how to display text or an image. As such , HTML is limited to a static, one-way
interaction with the user.
To add functionality to your web page you need the scripting language. JavaScript is one of the
most popular scripting languages for the internet. It works in all major browser.
JavaScript
JavaScript is a scripting language with a very simple syntax. It is used to add interactivity to your
webpages.
JavaScript provides web page authors with the power to reach a very high level of interaction
between the user and the document.
If you want to run the same JavaScript on several pages without having to write the same script
on every page. You can write a JavaScript in an external file.
For example
Document.write() method
This document.write() method is used for displaying the text on the browsers window. It uses ab
object called “document”. Which refers to the current document on the browsers
HTML tags can use also be included in the JavaScript code to generate HTML elements that will
be displayed in the browser window. Once the browser receives a string from the
document.write() method.
- The scripting language has to be written within <SCRIPT> … </SCRIPT> tags in s HTML
document.
- The <SCRIPT> … </SCRIPT> tags can either be written in the <HEAD> or <BODY> of HTML
document
- A program can have more than one of the <SCRIPT> … </SCRIPT> tags
- JavaScript is a case sensitive language
- Using a semicolon at the end of the statement is optional. Using semicolons makes it
possible to write multiple statement on one line.
JavaScript variables
Variables are the name assigned to a memory location that can be used for storing data.
Its valuables can change during the execution of a script. A variable can have a short
name, like x, or more descriptive name, like Fname. These variables, by default, hold on
one value at a time. If you try to assign another value then the previous one is
overwritten.
You can declare a variable in JavaScript by using var along with the variable name.
JavaScript operator
Arithmetic operators
Comparison/Relational operators
Logical operators
String operators
Comparison operator
Comparison operators are used to test if two variable relate to each other in the
specified way. These returns values which are either True or False.
Logical operator
String operators
A string is a set of characters. To join two or more string values together, you use the
plus ‘+’ operator. String concatenation operator.
Methods for the window object
Window.alert () method
window.alert () is a method of the window object. It is the simplest dialog box used to
display a short message to the user in a separate small window.
The syntax for the alert box is:
Window.alert (message)
Window.confirm() method
The confirm box includes both OK and Cancel buttons. Thus method returns the value
True if OK is oressed and False if Cancel is pressed.
Window.confirm (message)
Or
Confirm (message)
Window.prompt() methid
The method is used for obtaining input from the user. It displays an Explorer User
Prompt dialog box with a message and and an input field.
Or