CBSC Computer Notes
CBSC Computer Notes
Patron
Shri C. Neelap
Deputy Commissioner, KVS RO Guwahati
School Co-ordination
Shri . K. Alung Khumba
Principal, KV NFR, Maligaon, Guwahati
Subject Expert
Dr. K. K. Motla, PGT(CS),
KV NFR, Maligaon, Guwahati
Sh. Rajendra Gavahle, PGT(CS),
KV NFR, Maligaon, Guwahati
Syllabus Content X
Quarter – April to June
Grids are two-dimensional arrays of lines similar to graph paper, except that you can adjust the
spacing and other features of the grid to the needs of your work.
The home grid is the basic reference system, defined by three fixed
planes on the world coordinate axes . The home grid is visible by default when you start 3ds Max, but
can be turned off with an option in the right-click viewport menu. You can use any view of the home
1|Page
grid as a construction plane or you can create a grid object and use that as a construction plane
instead.
“Orthogonal” is a term used to describe two vectors that are perpendicular (at 90 degrees) to each
other. In 3D space, when the X, Y, or Z-Axes are not perpendicular, they are considered “non-
orthogonal” and the FBX plug-in does not support their representation as a matrix.
Because the FBX plug-in assumes that there is always a 90-degree angle between the X, Y, and Z
axes, it can support only orthogonal matrices. Any transformed axes that have non-orthogonal TRS
matrices are ignored by the FBX plug-in, so it does not import or export effects created when axes
are not orthographic.
Perspective Views: most closely resemble human vision. Objects appear to recede into the distance,
creating a sense of depth and space. For most 3D computer graphics, this is the view used in the
final output that the client sees onscreen or on the page. Perspective view of the ice-cream shop
There are three ways to create a perspective view in a viewport perspective view, camera view, and
light view.
A camera view requires that you first create a camera object in your
scene. The camera viewport tracks the view through the perspective of
that camera. As you move the camera (or target) in another viewport, you see the scene swing
accordingly. If you alter the camera's field of view on the Modify command panel, you see the
changes as they are applied.
2|Page
Creating Objects & Selecting Objects.
With some variations, the steps shown in the following images apply to
creating any type of object on the Create panel. For specific examples,
see the Procedures section in any object's topic.
2. Click one of the buttons at the top of the Create panel. For example, (Geometry).
3. Choose the subcategory Standard Primitives from the list.
• Click the button for the type of object you want to create.
The button highlights, showing that it is active. Four rollouts
appear Name and Color, Creation Method, Keyboard Entry,
and Parameters.
To choose a creation method (optional):
You can accept the default method and skip this step.
• Choose a method in the Creation Method rollout.
1. Put the cursor at a point in any viewport where you want to place the object, and hold the
mouse button down (do not release the button).
2. Drag the mouse to define the first parameter of the object; for example, the circular base of a
cylinder.
3. Release the mouse button. The first parameter is set with this release. In some cases, such
as Sphere, Teapot, and Plane, this completes the object. You can skip the remaining steps.
4. Move up or down without touching the mouse button. This sets the next parameter; for
example, the height of a cylinder.
If you want to cancel: Until you complete the next step, you can cancel the creation
process with a right-click.
5. Click when the second parameter has the value you want, and so on.
The number of times you press or release the mouse button depends on how many spatial
dimensions are required to define the object. (For some kinds of objects, such as Line and Bones, the
number is open-ended.)
4|Page
4. You can link an object to a closed group. When you do, the object becomes a child of the
group parent rather than any member of the group. The entire group flashes to show that
you've linked to the group.
5. A child inherits the transformations (move, rotate, scale) applied to the parent, but the child's
transformations have no effect on the parent. If you want the child not to inherit the transforms,
use the Link Inheritance (Selected) Utility or use the controls found in Link Info in the Hierarchy
panel.
6. You can also create hierarchical linkages using Schematic View. Use the Connect button on
the Schematic View toolbar to create hierarchical linkages between nodes.
Transforming Objects:
When you create any object, 3ds Max records its position,
rotation, and scale information in an internal table called a
transformation matrix. Subsequent position, rotation, and scale
adjustments are called transforms.
An object can carry any number of modifiers, but only one set of transforms. Although you can
change transform values from frame to frame, each object always has only one position, one
rotation, and one scale transform.
You can animate your transforms by turning on the Auto Key button and then performing the
transform at any frame other than frame 0. This creates a key for that transform at the current
frame.
5|Page
SUMMARY
1. 3D means three-dimensional, i.e. something, that has width, height and depth (length).
2. “Orthogonal” is a term used to describe two vectors that are perpendicular (at 90 degrees) to
each other. In 3D space, when the X, Y, or Z-Axes are not perpendicular, they are considered
“non-orthogonal”.
3. There are three ways to create a perspective view in a viewport perspective view, camera
view, and light view.
4. When you create any object, 3ds Max records its position, rotation, and scale information in an
internal table called a transformation matrix.
5. Subsequent position, rotation, and scale adjustments are called transforms.
EXERCISES
i. 3D means________________dimension.
ii. 3D perception is also called _________________perception.
iii. Subsequent position, _____________and______________ are referred as transforms.
iv. In 3D space when X,Y or Z Axes are not ___________they considered “non -
orthogonal”.
6|Page
Lesson-2
Animation in 3D Max
Animation
8|Page
artists by having them draw only the important frames,
called keyframes.
Assistants could then figure out the frames that were required in between the key frames. These
frames were (and still are) called tweens. Use 3ds Max as your animation assistant. As the master
animator, you create the key frames that record the beginning and end of each transformation. The
values at
these key frames are called keys. 3ds Max calculates the interpolated values between each key
value, resulting in tweened animation.
It combines different layers of animation automatically. The whole process controls by program,
determines which animation layer should be used and controls the method of combination like
override, additive, overly or and the amount of density.
9|Page
• Position
• Rotation
• Scale
• Placement
This section presents brief topics to help you quickly start learning how to transform objects and how
to animate your transforms.
In some cases, an object might fail to move or rotate, even when the proper command is active and
the object is selected. This could be due to one of the following reasons:
1. On the main toolbar, click one of the three transform buttons: (Select And Move),
(Select And Rotate), or (Select And Uniform Scale). These buttons are usually
referred to as Move, Rotate, and Scale.
Alternatively, to position an object on another object's surface, click (Select And Place).
10 |
Page
3. Drag the mouse to apply the transform.
If you start the drag over an unselected object, it becomes selected and is also
transformed.You can restrict transforms to one or two axes easily with the Using
Transform Gizmos.
Animation Playback
Play/Stop
The Play button plays the animation in the active viewport. If you click another viewport to
make it active, the animation continues playing in that viewport. When the animation is playing, the
Play button becomes a Stop button. The Play button is a flyout for playing only the animation of
selected objects.
11 |
Page
The animation plays in the viewport. The Play button becomes a Stop button.
The speed of the animation playback is determined by the settings in the Time
Configuration dialog, the complexity of the scene and the speed of the graphics card and
processor.
2. In the Time Configuration dialog Playback group, turn off Real Time.
i. The Direction buttons are now available.
3. Turn on Reverse and click OK.
4. Click (Play Animation).
i. The animation plays backward.
5. To play the animation front-to-back and then back-to-front in a continuous loop, turn on Ping-
Pong as the Direction.
Acceleration
12 |
Page
Acceleration is measured in units per frame per frame, where the
unit is the current 3ds Max system unit. That is, the acceleration is
determined by the rate at which the speed changes per frame.Use
AccelerationTurn on to have the motion synthesis engine consider
delegate acceleration in determining whether to activate the state.
Range group
When you choose Range, the motion synthesis engine activates the
clip when the delegate's acceleration falls inside the specified range.
Min/Avg/Max display
After you synthesize the Master Motion Clips, displays delegates'
minimum, average, and maximum acceleration.
Min
Set a minimum acceleration value for the range.
Max
Set a maximum acceleration value for the range.
When you choose Unique, the motion synthesis engine activates the clip when the delegate's
acceleration matches a specific value, optionally with a rising, falling, or constant value before or after
the specified value.
Value
Set a unique acceleration value.
13 |
Page
These settings let you scale the rate at which the animation is played, depending upon the
acceleration of the delegate.
Scale Animation
For example, as a bird accelerates, its wings beat more rapidly. Scaling an animation scales the keys
of the animation.
Percentage
Specify how much to alter the playback speed based upon the difference between the delegate's
acceleration and the Base Acceleration setting.
For example, if a delegate is accelerating 50 percent faster than the base acceleration, and the Scale
Percentage value is 50, then the playback speed is scaled up by 25 percent.
Base Acceleration
Specifies the delegate acceleration at which the animation should be played back at its normal rate.
Time Configuration
The Time Configuration dialog provides settings for frame rate, time display, playback, and animation.
You use this dialog to change the length of your animation, or stretch or rescale it
• Status bar > Time controls > (Time Configuration) > Time Configuration dialog
14 |
Page
3. Do one of the following:
• Set End Time to specify the end of your active time segment.
• Set Length to specify the amount of time in the active time segment and
automatically set the correct End Time.
You can enter positive or negative values in any spinner, but you must use the same format used by
the time display.
This procedure adds new frames to the end of your animation, without affecting your existing work.
1. In the Time Configuration dialog Animation group End Time field, enter the number
of the last frame of the animation.
For example, if your existing animation is 100 frames long and you want to add 50
frames, enter 150.
2. Click OK.
The number you entered is now the new length of the animation, shown on the time
slider.
• Inthe Time Configuration dialog Animation group, enter the frame number in the
Current Time field, and press .
15 |
Page
To set the frame rate of your animation:
In the Time Configuration dialog Frame Rate group, do one of the following:
1. In the Time Configuration Playback group, turn off the Real Time.
2. Choose the direction of the animation playback by selecting Forward, Reverse, or
Ping- Pong.
3. Play the animation in the viewport using (Play Animation) or the / key.
3. Play the animation in the viewport using (Play Animation) or the / key.
1. In the Time Configuration Playback group, turn off Active Viewport Only. Click OK.
2. Play your animation.
• In the Time Configuration Playback group, be sure you have Real Time turned on. If
Real Time is not on, the sound will not play back during the animation.
Interface
These are the controls for the Time Configuration dialog. You can
display this dialog by right-clicking any of the time control buttons to
the right of the Auto Key button.
16 |
Page
Frame Rate group
These four option buttons, labeled NTSC, Film, PAL, and Custom let you set the frame rate in
frames-per-second (FPS).
The general process of creating links is to build the hierarchy from child to parent. You click Select
and Link on the toolbar, select one or more objects as children, and then drag the link cursor from the
selection to a single parent object. The selected objects become children of the parent object.
Once objects are linked, any transformations applied to the parent are also applied to its children. For
example, if you scale the parent to 150%, the size of its children and the distance between the
children and the parent are also scaled by 150%.
Unlinking Objects
Click Unlink Selection to remove the link from selected objects to their parents. Any children of the
selected object are unaffected.
You can quickly unlink an entire hierarchy by double-clicking the root object to select the object and
all of its children. Then click Unlink Selection..
You should establish links before you begin animating objects. The linkage of objects with Select and
Link cannot be animated; the link remains in force throughout the entire animation.
If you want your objects to be linked during one part of the animation but not another, you can a Link
constraint to change the linkage at specific frames.
17 |
Page
Editing tools:
Select Modifiers
Controls on the Bone Editing Tools rollout let you create and modify bone geometry and structure,
and set bone color for one or more bones
Interface
Bone Pivot Position group
Lets you change the lengths of bones and their positions relative to one
another.
When this button is on, you can change the length of a bone by moving
its child bone. In effect, you can scale or stretch a bone by moving its
child bone while in this mode. You can use this tool both before and
after assigning an IK chain to the bone structure.
When Bone Edit Mode is on, you cannot animate, and when Auto Key or Set Key is on, Bone Edit
Mode is unavailable. Turn off Auto/Set Key to edit bones.
Create Bones Begins the bone-creation process. Clicking this button is the same as clicking Create
panel Systems Bones System.
Create End Creates a nub bone at the end of the currently selected bone. If the selected bone is not
at the end of a chain, the nub is linked in sequence between the currently selected bone and the next
bone in the chain.
Remove Bone Removes the currently selected bone. The bone’s parent bone is stretched to reach
the removed bone’s pivot point, and any children of the removed bone are linked to its parent. Any IK
chains that included the removed bone will remain intact.
18 |
Page
Connect Bones Creates a connecting bone between the currently selected bone and another bone.
When you click this button, a dotted line appears in the active viewport from the first selected bone.
Move the cursor to another bone to create a new connecting bone. The first selected bone will
become a parent to the connecting bone, which is in turn a parent to the second selected bone.
Delete Bone Deletes the currently selected bone, removing all its parent/child associations. A nub is
placed at the end of the deleted bone’s parent. Any IK chains that included this bone become invalid.
Reassign Root Makes the currently selected bone the root (parent) of the bone structure.
Refine Splits a bone in two. Click Refine, and then click a bone where you want it to split.
Mirror Opens the Bone Mirror dialog (see following), which lets you create mirror copies of selected
bones without changing the sign of the bones' scale. Instead, Mirror flips one of the bone axes: Y or
Z. You can specify the mirroring axis and the flip axis with the dialog controls.
Mirror Axis Choose an axis or plane about which the bones will be mirrored: X/Y/Z or XY/YZ/ZX.
Bone Axis to Flip To avoid creating a negative scale, choose the bone axis to flip: Y or Z.
Offset The distance between the original bones and the mirrored bones. Use this to move the
mirrored bones to the other side of the character.
Edit Modifiers
To be demonstrated by teacher in practical class
Sub-Object Selection
19 |
Page
If the modifier supports sub-object selection, the plug-in must provide methods to allow the system to
manipulate the sub-object components of the modifier. When a modifier's parameters are being
edited, it has the option of providing the system with different levels of sub-object selection. There are
two types of sub-object selection:
Selecting Sub-Objects
region away from the object, or first activate (Select Object) on the main toolbar.
2. On the modifier stack display, click (the plus-sign icon to the left of the name of the
modifier or editable object).
3. On the stack display, choose the kind of sub-object geometry you want to work with:
for example, Vertex, Face, or Edge. Each sub-object selection level has rollouts with
their own sets of options.
The surface formats (mesh, poly, and so on), automatically remember the most recent selection for
each sub-object level: vertex, edge, and so on (there is overlap in some cases, such as poly edge
and border). These selection sets are saved with the file. With sub-object selections, you have these
options:
• Choose one of the selection sets to pass geometry up the stack to other modifiers.
Only one selection set is active at a time.
• Change to one of the other selection sets at any time by activating its sub-object
level.
• Use named selection sets for sub-object selections you want to reuse.
•
• Apply any options supplied for the kind of object and the selection level.
• Apply standard transforms: Move, Rotate, Scale. For more information, see
Transforming a Sub-Object Selection, following.
• Apply object-space modifiers (Bend, Taper, and Twist, for example) to perform useful
modelling operations.
21 |
Page
• Apply object-space modifiers (UVW Map or Smooth, for example) to perform useful
surfacing operations.
• Bind a space warp to the selection. The rest of the object is unaffected by the warping.
• Use the toolbar commands Align, Normal Align, and Align To View with face
selections.
Using an editable mesh, poly, patch, or spline, you can directly transform any sub-
object selection. However, “Select” modifiers like Mesh Select and Spline
Select enable only selection.
1. Add an XForm modifier to the stack, following (or somewhere above) the Select
modifier.
2. In the stack, open the Select modifier and make a sub-object selection.
3. Choose XForm in the stack. You then transform the XForm gizmo, which applies the
transform to the selection.
22 |
Page
control is not available for the active level, it might be grayed out, or simply might not
appear at all.
1. Create or select a spline Modify panel Right-click spline entry in the stack
display Convert To: Editable Spline
2. Create a line Modify panel
3. Create or select a spline Right-click the spline Transform (lower-right) quadrant of
the quad menu Convert To: Convert to Editable Spline
Editable Spline provides controls for manipulating an object as a spline object and at
three sub-object levels: vertex, segment, and spline.
The functions in Editable Spline are the same as those in the Edit Spline modifier.
The exception is that when you convert an existing spline shape to an editable spline,
the creation parameters are no longer accessible or animatable. However, the spline's
interpolation settings (step settings) remain available in the editable spline.
SUMMARY
23 |
Page
3. A transform is an adjustment of an object’s position, orientation, or scale, relative to the 3D
world (or world space) in which you are working.
4. Acceleration is measured in units per frame per frame, where the unit is the current 3ds
Max system unit. That is, the acceleration is determined by the rate at which the speed
changes per frame.
5. The general process of creating links is to build the hierarchy from child to parent.
6. Offset is the distance between the original bones and the mirrored bones. Use this to move
the mirrored bones to the other side of the character.
EXERCISES
ii. If the object in the pipeline is a triangle object, then sub object selection level might be
things like vertex, face, edge etc.
iii. To avoid creating a negative scale, choose the bone axis to flip X or Y.
24 |
Page
Webpages
You will learn
Browser Support
The first web browsers had support for text only, limited to a
single font in a single color. Later came browsers with support
for colors and fonts, and even support for pictures!
The support for sounds, animations, and videos is handled
differently by various browsers. Different types and formats
are supported , and some formats require extra helper
programs (plug-ins) to work.
26 |
Page
Common Video Formats
So
un
d
For
ma
ts
27 |
Page
Embedding Audio File.
Method 1
3. You'll add 4 parameters to the object. The first is "src" that tells the browser where to find
the sound file. In this example, the sound file is eureka.wav and is found in the same
directory as the Web page:
<param name="src" value="eureka.wav" />
4. If you want the sound file to play immediately after it's loaded, make the autostart parameter
"true" otherwise make it "false":
<param name="autostart" value="true" />
5. The parameter autoplay is similar to autostart, just used by other browsers, set it the same as
the autostart parameter:
<param name="autoplay" value="true"/>
6. Use the controller parameter to tell the browser if a controller should be displayed to give
your readers more control over the sound:
<param name="controller" value="true" />
8. Add the following four attributes that are the same as the parameters to the object:
<embed src="eureka.wav" controller="true" autoplay="true" autostart="True" />
9. Add the correct MIME type for your sound file into the type attribute:
28 |
Page
<embed src="eureka.wav" controller="true" autoplay="true" autostart="True"
type="audio/wav" />
10. Add the plugins page attribute so that people who don't have the correct plugin for your sound
file can go download it. For WAV files, recommended QuickTime:
11. When you're done, your HTML should look like this:
<object>
<param name="autostart" value="true">
<param name="src" value="eureka.wav">
<param name="autoplay" value="true">
<param name="controller" value="true">
<embed src="eureka.wav" controller="true" autoplay="true" autostart="True"
type="audio/wav" />
</object>
Method 2
Make a hyperlink directly to the audio file using the following code (change
"audiofilename.wmv" to your own file name):
A link is created like this: Click here to listen audio. When the end user clicks this hyperlink,
their Windows Media Player will open and load the audio file for playing.
2. Create your video as a .mov or .mp4 file - and then upload it to your Web server
3. Write down the full URL to your video file - you'll need it when you write your HTML.
Class id="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B"
codebase=http://www.apple.com/qtactivex/qtplugin.cab
5. You'll also want to set the width and height of the object - set the width to the width of
the movie and the height to the height plus 15-20 pixels extra to include the controls.
8. The only parameter that you need is the src parameter - this tells the browser where to
find the movie to play. Set the src attribute to the URL of your movie:
9. Some other parameters that can be useful to control your video and make it more user-
friendly are:
controller - this can be true or false. Remember that most people get very
frustrated if they cannot control multimedia elements on Web pages that they visit.
So I strongly recommend setting this to true.
autoplay - this can be true or false. Autoplay also annoys customers. They want to
decide when and whether to watch the video. So I strongl recommend setting this
to false.
10. Inside the <object> tag, place the following parameters:
If it is very important to you that all your pages validate, then you should not include this
section. But remember that only people with some browsers like Safari and Opera will
be able to view your video.
30 |
Page
The embed tag should look like this. Note that all the fields are the same as the :
</object>
1. Copy the SWF file to the same folder as the HTML document.
2. In Dreamweaver, select the location of the page where you wish to add the Flash content
(including inside a div, table cell or frame).
3. Click the Insert Flash button in Dreamweaver's Object palette, or choose Insert> Media >
Flash. Browse to and choose the SWF file.
4. Upload both the SWF and HTML files to your Web server, placing them in the same directory.
Web page must contain tags that reference the actual Flash movie file to be opened and
played. These tags are the <OBJECT> and <EMBED> tags.
The OBJECT tag is used by Internet Explorer on Windows and the EMBED is used by
Netscape Navigator (Macintosh and Windows) and Internet Explorer (Macintosh) to direct the
browser to load the Macromedia Flash Player.
2. Copy the HTML code included in the <object> and <embed> tags (see example below) and
paste it into the existing HTML document. This should contain the <OBJECT> and <EMBED>
tags
31 |
Page
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/
swflash.cab#version=6,0,0,0" width="777" height="528" id="tech" align="middle">
<param name="allowScriptAccess" value="sameDomain" />
<param name="movie" value="showcase/flash/fashionshow.swf" />
<param name="quality" value="high" />
<embed src="showcase/flash/fashionshow.swf" quality="high" width="777"
height="528" name="tech" align="middle" allowScriptAccess="sameDomain"
type="application/x-shockwave-flash"
pluginspage="http://www.macromedia.com/go/getflashplayer" />
</object>
In this case, showcase/flash/ is the folder directory, while the fashionshow.swf is the SWF file
name.
3. Open the existing webpage page, and paste the <object> and <embed> tags into the
desired location in the body of the document. This can also be pasted into a table cell or
frame.
Change the height and width parameters to match the height and width of the movie
dimensions or use percentage values, if desired.
5. Upload the HTML and SWF files to the same folder on the Web server.
SUMMARY
32 |
Page
1. Multimedia comprises text, sound, graphics, image and video. Multimedia comes in many
different formats.
2. Pictures, music, sound, videos, records, films, animations are example of multimedia.
3. The first web browsers had support for text only, limited to a single font in a single color.
4. Plug-ins are the extra helper program of web browser.
5. MPEG, AVI, and WMV are example of common video format.
6. MIDI, RealAudio, and WMA are example of audio format.
EXERCISES
33 |
Page
Lesson-4
Web Scripting using JavaScript
You will learn
Example:
<script type="text/javascript">
<!--
var name = "Ali";
var money;
money = 2000.50;
//-->
</script>
The scope of a variable is the region of your program in which it is defined. JavaScript variable will
have only two scopes.
• Global Variables: A global variable has global scope which means it is defined everywhere in
your JavaScript code.
• Local Variables: A local variable will be visible only within a function where it is defined.
Function parameters are always local to that function.
<script type="text/javascript">
<!--
var myVar = "global"; // Declare a global variable
function checkscope( ) {
var myVar = "local"; // Declare a local variable
document.write(myVar);
}
36 |
Page
//-->
</script>
• You should not use any of the JavaScript reserved keyword as variable name.
• JavaScript variable names should not start with a numeral (0-9). They must begin with a letter
or the underscore character.
• JavaScript variable names are case sensitive.
The following are reserved words in JavaScript. They cannot be used as JavaScript variables,
functions, methods, loop labels, or any object names.
37 |
Page
abstract else instanceof switch
boolean enum int synchronized
break export interface this
byte extends long throw
case false native throws
catch final new transient
char finally null true
class float package try
const for private typeof
continue function protected var
debugger goto public void
default if return volatile
delete implements short while
do import static with
double in super
38 |
Page
+ Adds two operands A + B will give 30
&& Called Logical AND operator. If both the operands are (A && B) is true.
non zero then then condition becomes true.
! Called Logical NOT Operator. Use to reverses the !(A && B) is false.
logical state of its operand. If a condition is true then
Logical NOT operator will make false.
39 |
Page
Operator Description Example
== Checks if the value of two operands are equal or not, if (A == B) is not true.
yes then condition becomes true.
> Checks if the value of left operand is greater than the (A > B) is not true.
value of right operand, if yes then condition becomes
true.
< Checks if the value of left operand is less than the value (A < B) is true.
of right operand, if yes then condition becomes true.
>= Checks if the value of left operand is greater than or (A >= B) is not true.
equal to the value of right operand, if yes then condition
becomes true.
<= Checks if the value of left operand is less than or equal to (A <= B) is true.
the value of right operand, if yes then condition becomes
true.
40 |
Page
The Assignment Operators:
41 |
Page
• if statement
• if...else statement
• if...else if... statement.
if statement:
The if statement allows JavaScript to make decisions and execute statements conditionally.
Syntax:
if (expression){
Statement(s) to be executed if expression is true
}
Example:
<script type="text/javascript">
var age = 20;
if( age > 18 ){
document.write("<b>Qualifies for driving</b>");
}
</script>
if...else statement:
The if...else statement is the next form of control statement that allows JavaScript to execute
statements in more controlled way i.e to choose from given options.
Syntax:
if (expression){
Statement(s) to be executed if expression is true
}else{
Statement(s) to be executed if expression is false
}
42 |
Page
Example:
<script type="text/javascript">
var age = 15;
if( age > 18 ){
document.write("<b>Qualifies for driving</b>");
}else{
document.write("<b>Does not qualify for driving</b>");
}
</script>
if...else if... statement: The if...else if... statement allows JavaScript to make correct decision out of
several conditions.
Syntax:
if (expression 1){
Statement(s) to be executed if expression 1 is true
}else if (expression 2){
Statement(s) to be executed if expression 2 is true
}else if (expression 3){
Statement(s) to be executed if expression 3 is true
}else{
Statement(s) to be executed if no expression is true
}
Example:
<script type="text/javascript">
var book = "maths";
if( book == "history" ){
document.write("<b>History Book</b>");
}else if( book == "maths" ){
document.write("<b>Maths Book</b>");
}else if( book == "economics" ){
document.write("<b>Economics Book</b>");
}else{
document.write("<b>Unknown Book</b>");
}
43 |
Page
</script>
Maths Book
Switch Case: You can use multiple if...else if statements, to perform a multiway branch. However,
this is not always the best solution, especially when all of the branches depend on the value of a
single variable.
Syntax:The basic syntax of the switch statement is to give an expression to evaluate and several
different statements to execute based on the value of the
expression. The interpreter checks each case against the switch (expression)
value of the expression until a match is found. If nothing {
matches, a default condition will be used. case condition 1: statement(s)
The break statements indicate to the interpreter the break;
end of that particular case. If they were omitted, the case condition 2: statement(s)
<script type="text/javascript">
var grade='A';
document.write("Entering switch block<br />");
44 |
Page
switch (grade)
{
case 'A': document.write("Good job<br />");
break;
<script type="text/javascript">
var grade='A';
document.write("Entering switch block<br />");
switch (grade)
{
case 'A': document.write("Good job<br />");
case 'B': document.write("Pretty good<br />");
case 'C': document.write("Passed<br />");
case 'D': document.write("Not so good<br />");
case 'F': document.write("Failed<br />");
default: document.write("Unknown grade<br />")
}
document.write("Exiting switch block");
</script>
45 |
Page
This will produce following result:
Iteration – Loops
A loop is a block of code that allows you to repeat a section of code a certain number of times;
perhaps changing certain variable values each time the code is executed.
This not only saves you the time and trouble of repeatedly typing the same lines of code, but also
avoids typing errors in the repeated lines.
JavaScript allows you to use the for, while, and do while loops.
JavaScript Code Here The JavaScript code for the loop will be inside the brackets here
1. Initialization: Here we initialize our counter to a starting value. The initialization statement is
executed before the loop begins.
2. Test condition: If condition is true then code given inside the loop will be executed otherwise
loop will come out.
46 |
Page
3. Iteration statement: The iteration statement where you can increase or decrease your
counter.
<script type="text/javascript">
<!--
for (var count=1;count<6;count+=1) {
document.write("I am part of a loop!<br />");
}
//-->
</script>
I am part of a loop!
I am part of a loop!
I am part of a loop!
I am part of a loop!
I am part of a loop!
While loop:
syntax : initialization;
while( condition )
Update expression;
Example:
count++;
Program to print
5 numbers using
a <script type="text/javascript"> basic while
var count = 1;
loop:
document.write("Starting Loop" + "<br />");
while (count <= 5)
{
document.write("Number : " + count + "<br />");
count++;
}
document.write("Loop stopped!");
</script>
Starting Loop
Number : 1
Number : 2
Number : 3
Number : 4
Number : 5
Loop stopped!
Window Object
The window object represents an open window in a browser.
If a document contain frames (<iframe> tags), the browser creates one window object for the HTML
document, and one additional window object for each frame.
48 |
Page
Some common Window Object Methods:
confirm() Displays a dialog box with a message and an OK and a Cancel button
getSelection() Returns a Selection object representing the range of text selected by the user
prompt() Displays a dialog box that prompts the visitor for input
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.
An alert dialog box is mostly used to give a warning message to the users.
<html>
<head>
<script type="text/javascript">
<!--
function Warn()
49 |
Page
{
alert("This is a warning message!");
}
//-->
</script>
</head>
<body>
<p>Click the following button to see the result: </p>
<form>
<input type="button" value="Click Me" onclick="Warn();" />
</form>
</body>
</html>
Nonetheless, an alert box can still be used for friendlier messages. Alert box gives only one button
"OK" to select and proceed.
A confirmation dialog box is mostly used to take user's consent on any option. It displays a dialog box
with two buttons: OK and Cancel.
If the user clicks on OK button the window method confirm() will return true. If the user clicks on the
Cancel button confirm() returns false. You can use confirmation dialog box as follows:
50 |
Page
<html>
<head>
<script type="text/javascript">
<!--
function getConfirmation(){
var retVal = confirm("Do you want to continue ?");
if( retVal == true ){
alert("User wants to continue!");
return true;
}else{
alert("User does not want to continue!");
return false;
}
}
//-->
</script>
</head>
<body>
<p>Click the following button to see the result: </p>
<form>
<input type="button" value="Click Me" onclick="getConfirmation();" />
</form>
</body>
</html>
This dialog box is displayed using a method called prompt() which takes two parameters (i) A label
which you want to display in the text box (ii) A default string to display in the text box.
This dialog box with two buttons: OK and Cancel. If the user clicks on OK button the window
method prompt() will return entered value from the text box. If the user clicks on the Cancel button the
window method prompt() returns null.
<html>
<head>
<script type="text/javascript">
function getValue(){
<body>
<p>Click the following button to see the result: </p>
<form>
<input type="button" value="Click Me" onclick="getValue();" />
</form>
</body>
</html>
On clicking button ‘Click Me’ prompt dialog box will appear on the screen.
52 |
Page
FUNCTIONS –USER DEFINED
A function is a group of reusable code which can be called anywhere in your programme. This
eliminates the need of writing same code again and again. This will help programmers to write
modular code. You can divide your big programme in a number of small and manageable functions.
Function Definition:
The most common way to define a function in JavaScript is by using the function keyword, followed
by a unique function name, a list of parameters (that might be empty), and a statement block
surrounded by curly braces.
The basic syntax is
shown here:
Example:
53 |
Page
<script type="text/javascript">
<!--
function sayHello()
{
alert("Hello there");
}
//-->
</script>
Calling a Function:
To invoke a function , you would simple need to write the name of that function as follows:
<script type="text/javascript">
<!--
sayHello();
//-->
</script>
Function Parameters:
We can pass different parameters while calling a function. These passed parameters can be captured
inside the function and any manipulation can be done over those parameters.
A function can take multiple parameters separated by comma.
Example: Let us do a bit modification in our sayHello function. This time it will take two parameters:
<script type="text/javascript">
<!--
function sayHello(name, age)
{
alert( name + " is " + age + " years old.");
}
//-->
</script>
54 |
Page
Note: We are using + operator to concatenate string and number all together. JavaScript does not
mind in adding numbers into strings.Now we can call this function as follows:
<script type="text/javascript">
<!--
sayHello('Zara', 7 );
//-->
</script>
A JavaScript function can have an optional return statement. This is required if you want to return a
value from a function. This statement should be the last statement in a function.
For example you can pass two numbers in a function and then you can expect from the function to
return their multiplication in your calling program.
Example:
This function takes two parameters and concatenates them and return resultant in the calling
program:
<script type="text/javascript">
<!--
function concatenate(first, last)
{
var full;
<script type="text/javascript">
<!--
var result;
55 |
Page
result = concatenate('Zara', 'Ali');
alert(result );
//-->
</script>
String Object
• Encapsulation . the capability to store related information, whether data or methods, together in
an object
• Aggregation . the capability to store one object inside of another object
• Inheritance . the capability of a class to rely upon another class (or number of classes) for use
of its properties and methods
• Polymorphism . the capability to write one function or method that works in a variety of different
ways
The String object let's you work with a series of characters and wraps Javascript's string primitive
data type with a number of helper methods.
Example:
var guitar_string = new String("Gagan");
OR
String Properties
Property Description
56 |
Page
EXAMPLE:
<body>
<script type="text/javascript">
var myname="John";
</script>
</body>
Result is :
String Methods
Method Description
57 |
Page
specified location through the specified number of
characters.
Example:
Result is : GaganSagan
Here is a list of each method, which returns a copy of the string wrapped inside the appropriate HTML
tag.
Method Description
58 |
Page
blink() Creates a string to blink as if it were in a <blink> tag.
fontsize() Causes a string to be displayed in the specified font size as if it were in a <font
size="size"> tag.
Example:
var text = "I am so mad I am red!";
document.write(text.fontcolor("red"));
This script places the following code into the page source:
<font color="red">I am so mad I am red!</font>
Math Object
The math object provides you properties and methods for mathematical constants and functions.
Syntax
Example:
59 |
Page
var pi_val = Math.PI; // pi_val =3.14159
var sq = Math.SQRT2; // sq = 1.414
Math Properties
Property Description
Math Methods
Method Description
pow() Returns base to the exponent power, that is, base exponent.
Example :
60 |
Page
var num =4;
document .write(“ SQURE ROOT OF NUM = “+ sqrt(num) );
Event
What is an Event?
When the page loads, that is an event. When the user clicks a button, that click, too, is an event.
Another example of events are like pressing any key, closing window, resizing window etc.
This is the most frequently used event type which occurs when a user clicks mouse left button. You
can put your validation, warning etc against this event type.
Example:
<html>
<head>
<script type="text/javascript">
<!--
function sayHello() {
alert("Hello World")
}
//-->
</script>
</head>
<body>
<input type="button" onclick="sayHello()" value="Say Hello" />
</body>
</html>
This will produce following result and when you click Hello button then onclick event will occur
which will trigger sayHello() function.
61 |
Page
Another most important event type is on submit. This event occurs when you try to submit a form. So
you can put your form validation against this event type.
Example:
<html>
<head>
<script type="text/javascript">
<!--
function validation() {
all validation goes here
.........
return either true or false
}
//-->
</script>
</head>
<body>
<form method="POST" action="t.cgi" onsubmit="return validate()">
.......
<input type="submit" value="Submit" />
</form>
</body>
</html>
The onmouseover event occurs when you bring your mouse over any element and theonmouseout
occurs when you take your mouse out from that element.
Example: Following example shows how a division reacts when we bring our mouse in that division:
<html>
62 |
Page
<head>
<script type="text/javascript">
<!--
function over() {
alert("Mouse Over");
}
function out() {
alert("Mouse Out");
}
//-->
</script>
</head>
<body>
<div onmouseover="over()" onmouseout="out()">
<h2> This is inside the division </h2>
</div>
</body>
</html>
The standard HTML 4 events are listed here for your reference. Here script indicates a Javascript
function to be executed agains that event.
63 |
Page
over an element
SUMMARY
1. One of the most fundamental characteristics of a programming language is the set of data
types it supports.
2. Variable is the stored memory location that can hold a value in it. Variables are declared with
the var keyword.
3. The scope of a variable is the region of your program in which it is defined. JavaScript variable
have only two scopes: Global and Local Variables
4. Global Variables is a global variable has global scope which means it is defined everywhere
in your JavaScript code.
5. Local Variables is a local variable will be visible only within a function where it is defined.
6. An Operator is a symbol that performs an operation. JavaScript language supports Arithmetic,
Comparison, Logical, Assignment, and Conditional Operators.
7. The if statement allows JavaScript to make decisions and execute statements conditionally.
8. The if...else statement is the next form of control statement that allows JavaScript to execute
statements in more controlled way i.e to choose from given options.
9. if...else if... statement: The if...else if... statement allows JavaScript to make correct decision
out of several conditions.
10. Switch case is one of the alternate of multiple if. Else…if…
11. A loop is a block of code that allows you to repeat a section of code a certain number of times;
perhaps changing certain variable values each time the code is executed.
12. The window object represents an open window in a browser
13. A confirmation dialog box is mostly used to take user's consent on any option. It displays a
dialog box with two buttons: OK and Cancel.
14. The prompt dialog box is very useful when you want to pop-up a text box to get user input.
Thus it enable you to interact with the user. The user needs to fill in the field and then click OK.
64 |
Page
15. A function is a group of reusable code which can be called anywhere in your programme. This
eliminates the need of writing same code again and again.
16. The math object provides you properties and methods for mathematical constants and
functions
17. An occurance of an activity is called an event.
18. The onmouseover event occurs when you bring your mouse over any element and
theonmouseout occurs when you take your mouse out from that element.
EXERCISES
i. _____________ is the stored memory location that can hold value in it.
ii. _____________ cannot be used as variable.
iii. An __________ is a symbol that performs an operation.
iv. ___________control statement allows JavaScript to execute statement in more
controlled way.
v. ____________is one of the alternate of multiple if….else….if.
vi. The _____________ object represents an open window in a browser.
vii. ____________ is mostly used to give warning message to the users.
viii. ____________ is a group of reusable code which can be called anywhere in your
program.
ix. ___________keyword is used to define function in JavaScript.
x. The _____________object provides you properties and methods for mathematical
constants and functions.
B. State true or false:
i. The onmouseover event occurs when you take out your mouse out from that
element.
ii. An occurrence of an activity is called event.
iii. Pow( ) method returns base to the exponent power.
iv. Encapsulation is the capability of a class to rely upon another class for use of its
properties and methods.
v. JavaScript function can have a optional return statement.
65 |
Page
vi. We are using * operator to concatenate string.
66 |
Page
Lesson-5
Operating Web based application
Positive Impacts:
68 |
Page
3. Reduce cost of availing the services.
4. Keep a tab on corruption to some extent.
5. Increased public participation.
6. Increase transparency & increased accountability of government offices
Negative Impacts:
E-BUSSINESS
What is E- Business?
E-BUSINESS refers to any form of transaction that uses an electronic medium to facilitate the
transaction.
Positive Impacts
Negative Impacts
E- LEARNING
What is E- Learning?
E-LEARNING is a flexible term used to describe a means of teaching through technology such
as a network, browser, CDROM or DVD multimedia platforms.
Positive Impacts
Negative Impacts
70 |
Page
Check Your Progress
True or False
Q.1 The return statement can return two values from a function at a time.
Q.2 A function can take multiple parameters separated by comma.
Q.3 A function is a group of reusable code which can be called anywhere in your programme.
72 |
Page