Professional Documents
Culture Documents
Contents
Lab Practical Week #1..................................................................................................................................5
Operating System (System Software)......................................................................................................5
Windows xp,7,8,10..............................................................................................................................5
MICROSOFT OFFICE (Application Software):............................................................................................6
Installation ( Steps ):............................................................................................................................7
Lab Practical Week#2..................................................................................................................................9
Some of Most commonly used email addresses and service providers...................................................9
Email account sign up:.............................................................................................................................9
Lab Practical Week#3................................................................................................................................13
Microsoft Word (word processor).........................................................................................................13
Ribbon ( toolbar ):.................................................................................................................................13
To create a new blank document:.........................................................................................................14
Inserting Page Numbers :...................................................................................................................14
Adding Line Numbers :......................................................................................................................14
Creating and Inserting Screenshots:..................................................................................................15
Checking the Spelling and Grammar of the Entire Document:..........................................................15
Checking the Spelling and Grammar Word-by-Word:.......................................................................16
Pre-Formatted Margins :....................................................................................................................16
Customizing Your Margins:................................................................................................................16
Turning off the AutoFormat:..............................................................................................................17
Using, Formatting, and Removing Styles:..........................................................................................17
Lab Practical Week #4................................................................................................................................20
Microsoft Word ( Continued).................................................................................................................20
Adding a Cover Page:........................................................................................................................20
Inserting a Page Border:....................................................................................................................20
Inserting a Table:...............................................................................................................................21
Inserting a Chart:...............................................................................................................................22
Inserting Clip Art:...............................................................................................................................22
CS101: Introduction to Computing
Description List:.................................................................................................................................45
Tables:...................................................................................................................................................46
Lab Practical Week #9................................................................................................................................51
Passive Web Pages:...............................................................................................................................51
Interactive Web Pages:..........................................................................................................................51
Interactive Forms :.................................................................................................................................52
Lab Practical Week #10..............................................................................................................................59
JavaScript (Client-side scripting)............................................................................................................59
Scripting:............................................................................................................................................59
Types of scripting:..............................................................................................................................59
New Concept: Client-Side Scripts.......................................................................................................60
Advantage of Client-Side Scripting :...................................................................................................60
Why JavaScript?.....................................................................................................................................61
What is JavaScript?................................................................................................................................61
JavaScript:..........................................................................................................................................61
Types of Objects................................................................................................................................68
Lab Practical Week # 11.............................................................................................................................69
Data types:............................................................................................................................................69
Variables:...............................................................................................................................................70
Declaration of Variable:.....................................................................................................................70
Initializing a Variable:.........................................................................................................................70
Operators:.............................................................................................................................................71
Conditional Statements:........................................................................................................................72
if Statement:......................................................................................................................................72
if-else Statement:..............................................................................................................................73
Multiple if Statements:......................................................................................................................73
Switch Statements:............................................................................................................................74
Loops:....................................................................................................................................................75
for Loop:............................................................................................................................................75
while Loop:........................................................................................................................................75
CS101: Introduction to Computing
do-while Loop:...................................................................................................................................76
Difference between while and do-while loop:...................................................................................76
Arrays:...................................................................................................................................................76
Lab Practical Week #12..............................................................................................................................80
Function:................................................................................................................................................80
Methods :..............................................................................................................................................82
CS101: Introduction to Computing
An operating system (OS) is system software that manages and controls the overall operation of
computer hardware.
Example:
Windows xp,7,8,10
Linux,UNIX
Mac OS X etc
Windows 7 Installation:
1. Start your computer. Press f2 or delete at start up to enter the bios menu. Select
First boot device as ‘CD ROM’ if you installing from DVD ROM. Second boot device
as ‘Hard Disk’ so that the computer boots from Hard disk if OS is not in DVD ROM.
Press f10 to save your settings and select yes to restart your computer.
2. Insert the installation disc for Windows 7 and start your computer. The computer
will ask you to ‘Press any key to boot from CD/DVD’. Press any key on your
keyboard and it will start loading the operating system from the CD.
3. After loading windows 7 successfully, it opens an install window. Enter the
Language time & currency format and keyboard or input method. Click ‘Next’. The
‘Install windows 7’ screen will appear.
4. Click ‘Install now’. Setup will start and you will see a message on the screen ‘Set
up is starting…’
5. Now it will show the License agreement screen. Check the ‘I accept the License
terms’ and click ‘Next’. The ‘Install windows’ wizard will appear.
6. Select Custom (Advanced) option. The screen will prompt you to select the
location to install windows. Click drive option (Advanced menu). Click on ‘New’,
you are then asked to allot a size on the disk for installation. Enter the appropriate
volume size and then click ‘Apply’ to create partitions for the installation, click
CS101: Introduction to Computing
‘Next’. Windows will start the installation. Now the installation status screen
appears. You will have to wait for the following tasks to get complete.
Copying Windows
Expanding Windows files
Installing features
Installing updates
Completing Installation
The computer will restart several times during this process so do not
worry.
7. After successful installation of Windows 7 it will ask you to specify the ‘computer
name’. It will also ask you enter a ‘User account’ and ‘Password’. Enter the
password in the respective field and also the password hint, click ‘Next’.
8. The setup key will open the ‘Product Key’ option. Enter the correct product key,
make sure that ‘Automatically activate windows when I am online’ check box is
selected and click ‘next’.
9. Now a window to set time on your computer will be displayed. Set the correct
‘Time Zone’, date and click ‘Next’ option.
10. The ‘Computer network location’ option will be displayed if your computer is
already connected to a network. Select ‘Network type’ and click ‘next’.
11. Windows will now finalize the setup and start to prepare your Windows 7
Desktop.
Products:
The versions available are made up of some or all or more of the following programs:
Installation ( Steps ):
1. Insert the Microsoft Office media disc into the DVD drive. Click "Start" followed by "Computer."
Double-click the disc drive if Windows fails to launch setup automatically.
2. Enter your product key when prompted and click "Continue." Read the license terms and then
check "I Accept the Terms of This Agreement." Click "Continue."
3. Click "Customize." Select the first program or tool from the list and then choose "Run From My
Computer," "Run All From My Computer," "Installed on First Use" or "Not Available" from the
options.
4. Repeat the previous step for each application or feature. Click "Install Now" to install
Microsoft Office to the laptop
CS101: Introduction to Computing
Email:
Short for electronic mail, email (or e-mail) is defined as the transmission of messages over
communications networks.
Email is a message that may contain text, files, images, or other attachments sent through a
network to a specified individual or group of individuals.
The first e-mail was send by Ray Tomlinson in 1971.
Gmail
Yahoo Mail
Outlook.com
Mail.com
1. Open the Gmail website. Click the blue “Create an account” button below the login box.
This will take you to the “Create your Google Account” page.
CS101: Introduction to Computing
2. Fill out the required information. You will need to enter your first and last name, your
birthday (for age verification), your gender, your phone number in case you lose access
to your account, and a verification email address. You also need to enter which country
you reside in.
3. Come up with a username Your username will become your new Gmail email address
and the password you entered will be the password for your email address.
4. Complete the CAPTCHA. This is a verification tool that ensures that a real person is
creating the account.
CS101: Introduction to Computing
7. Click Next Step once more. Your Gmail account has been created.
CS101: Introduction to Computing
Ribbon ( toolbar ):
“The Ribbon” is the professional term for the Microsoft Word toolbar, and is a part of
many Microsoft programs, including Outlook, Excel, and PowerPoint. You can use the
Ribbon to access virtually every feature of Word.
The File tab provides options for basic administrative tasks involving your
document, such as saving, printing, and opening a new document.
The Home tab provides options to edit aspects of the basic formatting your
document, such as the font (type, size, color, etc.), text alignment, and creating
bulleted or numbered lists.
The Insert tab provides options to place visual enhancements in your document,
such as pictures, tables, and charts.
The Page Layout tab provides options for more advanced formatting of your
document, such as margins, page orientation (i.e. portrait/landscape), and size.
The References tab provides options for using various citations in your document,
such as footnotes, bibliographies, and captions.
The Mailings tab provides options for sending out your document, such as selecting
recipients and inserting a greeting line
The Review tab provides options for editing your document’s content, such as a
Spelling and Grammar check, a translator, and inserting comments in specific areas.
CS101: Introduction to Computing
The View tab provides options for examining your document, such as a full screen
view, print previewing, and zooming in or out.
Open Microsoft Word and Microsoft Word will open up automatically into a new
document ready for you to start typing.
If Microsoft Word is already opened but you wish to start a new document, click File at
the top left-hand corner of your document.
A new document will open up. You’re now ready to type into your document.
Select the Insert tab and select the Page Number option. A list of options appears.
Select your preferred option. The page numbers appear in the place you have selected.
Select the Page Layout tab and Select the Line Numbers option and Scroll through
the options and select your preference.
Open the window(s) you wish to capture on your desktop and Press the
PrintScreen/SysRq key (located in the upper right of your keyboard). Windows copies
your entire screen. Note that this key is sometimes abbreviated to PrtScrn or PrtSc.
Open a new Microsoft Word document and Press the Paste option on the ribbon at the
top, or the Ctrl and V keys simultaneously. Either method inserts the copied screenshot.
Select the Review tab and Select on the Spelling & Grammar icon and Choose the
appropriate correction from the suggestions that Word presents.
Select the Change button to apply the correction and If you wish to ignore Word’s
suggestions, select Ignore or Add to Dictionary.
CS101: Introduction to Computing
Pre-Formatted Margins :
Select the Page Layout tab and Select the Margins option. A drop-down menu with
pre-formatted options appears
Select your preference. Word automatically applies your changes.
CS101: Introduction to Computing
Follow Steps 1 and 2 of Pre-Formatted Margins and Select the Customize Margins
option at the bottom of the drop-down menu. A box appears on your screen. Fill in
the opinions according to your preferences and Select OK.
There are many positive aspects of Microsoft Word’s AutoFormat features, which can
format bulleted lists, symbols, and more. However, you can to turn it off and customize
your document to your own personal preferences
Select the File tab and Select the Options choice from the tab. A box appears on your
screen .Now Select Proofing from the menu on the left-hand side of the box and
Select the AutoCorrect Options button from the options that appear. Select the
option you wish to customize.
Click to select or clear the checkboxes beside the options that you want to enable or
disable. If you choose to clear them, you can then format these items based on your
preferences. Select OK. This box disappears, and only the “Proofing” box remains.
Select OK on the “Proofing” box to confirm your preferences.
Styles are formatting characteristics that you can apply to text, titles, and headings in your
document. You can use one of the pre-formatted options Word provides or customize your
own.
Using Styles
Select the Home tab and Select the text you wish to style. In the Styles box, select
the style you would like to use. For additional styles, select the down arrow on the
right-hand side of the Styles box.
Formatting Styles
Select the Change Styles option. A drop-down menu appears. Scroll through the
options and select your preferences. You can make changes to colors, fonts, and
more.
Removing Styles
Select the styled text you want to remove and Select the Normal option from the
Styles Ribbon. Your text switches back to your default font and font size.
Confirm that the document you are working on is already saved on your computer.
Select the File tab.
Select the Options choice from the tab. A box appears on your screen.
Select the Save option from the menu on the left-hand side of the box.
CS101: Introduction to Computing
You can use a cover page to provide some basic information about your document. Word
offers approximately twenty cover page templates that you can choose for your document.
Select the Insert tab from the Ribbon. Choose the first option on the left, Cover Page.
Scroll through the templates Word offers.
Select the Page Layout tab and Select the Page Borders option near the center.
CS101: Introduction to Computing
A box with multiple border options appears on your screen.Select your preference
and click OK.
Inserting a Table:
Tables are an efficient way to display information in a concise and simple manner. You can
use tables for presentations, tutorials, articles, and more.
Inserting a Chart:
Select the Insert tab. Select the Chart option. A box appears on your screen.
Select the type of chart you want to insert into your document. Select OK. Your
screen splits, and the chart appears on the left in a Word document, while a
Microsoft Excel spreadsheet with the chart’s dimensions appears in another
The term “Clip Art” refers to the pre-made images Word has stored that you can use to
illustrate your document. You can browse through many different options, or search for a
specific image.
Select the Insert tab. Select the Clip Art option. A search box appears on the right
side of your screen.
CS101: Introduction to Computing
Type your search terms in the entry field labeled Search for. Your search results
appear below. Scroll through and select the image that you would like to use in your
document
You can insert your own images into a Word document to complement a set of directions, a
presentation, or anything similar. You can insert any images saved on your computer into
your document.
Browse through your folders until you find the picture you wish to insert.
Select the Insert option. Word inserts the selected image into your document.
CS101: Introduction to Computing
Microsoft Excel:
The purple File button, located in the top left corner of your screen, replaces the Office
button found in Excel 2007.
Saving of file
Printing
Opening a new and old file
Sending a file Online
Protected View
In an effort to increase Office 2010’s security, Microsoft has instituted this feature
across all its products. Documents that are opened froman
―untrusted‖source(i.e.,aspreadsheetdownloadedfromGmailoropened from Outlook) will
appear in so-called Protected Mode. In Protected Mode, you cannot edit, print, or save files
to yourcomputer.
CS101: Introduction to Computing
The Quick Accesstoolbar, which used to be located to the right of the Office button, is now
directly above the Filebutton. By default, itcontains the three most frequently used buttons:
Save, Undo, andRedo.
EXCEL TERMINOLOGY:
To understand Excel better, you should familiarize yourself withthe following terminology:
spreadsheet, workbook, andworksheet.
Worksheet
CS101: Introduction to Computing
In order to enter data in Excel and/or create functions and formulas,you should be able to
identify the active—or selected—cell(s).
Press Tab to move right, Shift+Tab to move left, Enter to move down and Shift+Enter
to move upward.
Entering Data
Click to select the cell where you wish to enter your data.
Type the new data into the cell.
FORMATTING SPREADSHEET:
Merging Cells
Especially when making headers for tables, it is often useful to merge two cells together.
Cells can be merged both vertically and horizontally. To mergecells:
Select the cells you wish to merge together.
CS101: Introduction to Computing
Wrapping Text
Select the cell or range of cells you wish to enable wrapping for.
Locate the Alignment area of the Home ribbon.
Click the Wrap Text button.
INSERTING FUNCTIONS
Calculating a Sum
Select on the cell into which you want to enter your function.
Type “ =sum( “
Select the range of cells you wish to sum. A blinking dashed border will be around the
cellrange.
Type “) “and press enter.
Function Library
Other Functions
And similarly we can find different functions there such as AVERAGE, COUNT,
IF(conditional-function), SIN, SUMIF and many others.
All formulas must begin with the = symbol. Excel will not recognize your
formula as a formula without an = as the first character.
Microsoft PowerPoint
Now that you have reviewed the terms, you are ready to use the tools to create a
PowerPoint presentation.
CS101: Introduction to Computing
1. When you first open PowerPoint, a new presentation will open. The default slide design is
a white background with black lettering.
2. To choose a new design background click on formatfrom the toolbar, and then select
slide design. Then simply click on the desired design.
3. Once you have selected the slide design, click in the placeholders to add the title and
subtitle of the presentation. If the PowerPoint is used to supplement a paper, then use the
title of the paper. If your paper does not have a subtitle, then you can include the names of
those who participated in the presentation.
CS101: Introduction to Computing
1. Now that the title slide is complete you are ready to create the next slide. To create a
new slide, click on the inserttab from the toolbar and then select new slide. You can also
click on the new slidetab located on the right side of the formatting toolbar.
5. The new slide that appears is the default layout. This has a title placeholder and a text
placeholder. Notice that different slide layout options automatically appear in the task
pane. To choose a different layout, simply click on one of the choices.
CS101: Introduction to Computing
7. If you need to delete a slide select editfrom the toolbar and then select delete slide. You
can also move the mouse cursor over the slide you want to delete in the slide/outlinetab.
Then right click on the slide, and select delete slide.
8. During the creation of the presentation, you can go back and forth between slides by
clicking on the slide you want to view in the slide/outlinetab.
9. To view a slide show of your presentation, select slideshowfrom the toolbar, and then
select viewshow. To move between sides, click the mouse anywhere on the screen.
These are the basic steps to completing an effective PowerPoint presentation. There
are other tools that can be used such as, inserting pictures (pictures from the internet
often have copy right restrictions), transitions between slides, and music. However,
music and sound effects are not generally acceptable for academic PowerPoint
presentations.
CS101: Introduction to Computing
HTML
HTML Tags
<tagname>content</tagname>
Tags are of two types:
Paired Tag i-e <body></body>
Singular Tag i-e <br>
HTML Example:
<html>
<head>
<title>Page Title</title>
</head>
<body>
</body>
</html>
CS101: Introduction to Computing
Heading Tags:
Result:
CS101: Introduction to Computing
Paragraph Tag:
Result:
Code:
<html>
<head>
</head>
<body>
<p>This text is <br> normal.</p>
<p><b>This text is bold</b>.</p>
<p>This text is normal.</p>
<p><i>This text is italic</i>.</p>
<p>This text is normal.</p>
<p><u>This text is underline.</u></p>
<p><em>This text is emphasized</em>.</p>
<h2>HTML <small>Small</small> Formatting</h2>
</body>
</html>
Result:
CS101: Introduction to Computing
More Tags :
HTML Attributes :
Example:
Align (center,left,right)
Width
Size
Shade/Noshade
Code Example:
Result:
CS101: Introduction to Computing
CS101: Introduction to Computing
HTML Lists:
Unordered list<ul></ul>
Ordered list<ol></ol>
Description list <dl></dl>
Unordered List:
An unordered list starts with the <ul> tag. Each list item starts with
the <li> tag.
Example Code:
<html>
<body>
<ul>
<li>Chapter 1</li>
<li>Chapter 2</li>
<li>Chapter 3</li>
</ul>
</body>
</html>
Example Result :
CS101: Introduction to Computing
Type (disc,circle,square)
Example Code:
<ul type="circle">
<li>Chapter 1</li>
<li>Chapter 2</li>
<li>Chapter 3</li>
</ul>
Example Result:
Ordered List:
An ordered list starts with the <ol> tag. Each list item starts with the <li> tag.
Example Code:
<ol>
<li>Chapter 1</li>
<li>Chapter 2</li>
<li>Chapter 3</li>
</ol>
CS101: Introduction to Computing
Example Result:
Type ( 1/A/a/i/I)
Example Code:
<ol type="A">
<li>HTML</li>
<li>Java</li>
<li>C++</li>
</ol>
Example Result:
Nested List:
<ul>
<li>Chapter 1</li>
<li>Chapter 2
<ul>
<li>List</li>
<li>Tables</li>
</ul>
</li>
<li>Chapter 3</li>
</ul>
Result:
CS101: Introduction to Computing
Description List:
The <dl> tag defines the description list, the <dt> tag defines the term (name), and the <dd> tag
describes each term:
<dl>
<dt>C++</dt>
<dt>Javascript</dt>
</dl>
Result:
CS101: Introduction to Computing
Tables:
Example Code:
<html>
<body>
<table>
<tr>
<td>Jill</td>
<td>Smith</td>
<td>50</td>
</tr>
<tr>
<td>Eve</td>
<td>Jackson</td>
<td>94</td>
</tr>
CS101: Introduction to Computing
<tr>
<td>John</td>
<td>Doe</td>
<td>80</td>
</tr>
</table>
</body>
</html>
Result:
Table Attributes:
Border
Width
Height
Background
Bordercolor
Bgcolor
Cell padding
Cell Spacing
CS101: Introduction to Computing
Example Code:
<tr>
<td>Jill</td>
<td>Smith</td>
<td>50</td>
</tr>
<tr>
<td>Eve</td>
<td>Jackson</td>
<td>94</td>
</tr>
<tr>
<td>John</td>
<td>Doe</td>
<td>80</td>
</tr>
</table>
CS101: Introduction to Computing
Result:
Colspan
Rowspan
Bgcolor
Background
Align
Valign
Result:
Result:
CS101: Introduction to Computing
CS101: Introduction to Computing
Web Pages are “Read Only” .it just provides information to the user
GUI Based
Example:
CS101: Introduction to Computing
Interactive Forms :
Form Attributes :
Name
Method (Post/Get)
Action
Elements of Form:
Text Field
Buttons
Text Area
Check Boxes
Scrollable List
Result:
Result:
Result:
CS101: Introduction to Computing
Complete Code:
Result:
CS101: Introduction to Computing
Complete Code:
Result:
CS101: Introduction to Computing
Complete Code:
Result:
</SELECT>
Complete Code:
Result:
CS101: Introduction to Computing
Result:
CS101: Introduction to Computing
Scripting:
You can create an attractive, colorful Web page just using HTML. But without some
scripting, the page will just sit there, unresponsive to user actions.
Types of scripting:
Scripts can run either on the Web server (server-side scripting) or on the user's
computer (client-side scripting).
Client-side scripting:
Client-side scripting generally refers to the class of computer programs on the web that
are executed client-side, by the user's web browser, instead of server-side (on the web server).
Languages:
The most widely used client-side scripting language is JavaScript, which was invented by
Netscape Communications.
Server-side scripting:
Server-side scripting is a technique used in web development which involves
employing scripts on a web server which produce a response customized for each user's
(client's) request to the website.
Languages:
There are a number of server-side scripting languages available, including:
Python
PHP
JavaScript using Server-Side JavaScript etc.
CS101: Introduction to Computing
Small programs that are a part of the Web page and run on the user’s (client’s) computer. They
interact with the user to collect info or to accomplish other tasks. Once it has been collected,
they may help pass the collected info on to a server-side script We’ll use JavaScript to do client-
side scripting. However, there are many other languages that can be used for that purpose, e.g.
VBScript.
Reduced server load as it does not have to send messages to the user’s browser about missing
or incorrect data.
Disadvantages :
Scripting Example:
<INPUT
type=“submit”
name=“sendEmail”
value=“Send eMail”
onMouseOver=
>
CS101: Introduction to Computing
Why JavaScript?
HTML is great for static Web pages; however, supports only rudimentary interactivity through
forms and hyperlinks .
JavaScript can be used (along with HTML) to develop interactive content for the Web
What is JavaScript?
A programming language specifically designed to work with Web browsers.
It is designed to be used for developing small programs – called scripts – that can be
JavaScript:
Is an interpreted language
Is object-based
Object Based?
Everything that JavaScript manipulates, it treats as an object – e.g. a window or a button
An object has properties – e.g. a window has size, position, status, etc.
Properties are modified with methods – e.g. a resize a window with resizeTo(150, 200)
Not Object-Oriented!
JavaScript is not a true object-oriented language like C++ or Java It is so because it lacks two key
features: A formal inheritance mechanism Strong typing Nevertheless, it does include many key
CS101: Introduction to Computing
concepts that are part of almost all objectoriented languages, and therefore is referred as an
object-based language
Object:
PropertiesObjects may have a single or several properties A property may have one of the
following values: Number -- Text -- Boolean Array -- Functions Objects (Example: “document”
– a property of the “window” object – is an object in itself. A “document” in turn may contain a
“form” object as a property, and then that “form” may contain a “button” property, which,
once again, is an object in itself)
CS101: Introduction to Computing
Referring to a Property:
Example: 1
<HTML>
<HEAD>
<SCRIPT>
function changeStatus() {
</SCRIPT>
</HEAD>
<BODY>
onMouseOver=“changeStatus()”>
CS101: Introduction to Computing
</FORM></BODY></HTML>
Result:
CS101: Introduction to Computing
Example 2:
Types of Objects
JavaScript objects
Objects that are part of JavaScript Examples: window, document
Browser objects
Objects that contain info not about the contents of the display, but the browser itself
Examples: history, navigator User-defined object
Now we have established what we mean by objects: a named collection of properties and
methods
We have also learnt how to change the properties of these objects by selecting a property
Methods are functions associated with an object that can be used to manipulate that object
Example:
window.close()
Here “close()” is a method that has been defined for the “window” object. Its function
alert()
confirm()
prompt()
close()
open()
focus()
blur()
setTimeOut()
Data types:
Variables:
Declaration of Variable:
Initializing a Variable:
var sum; (After execution of 1st statement data type of sum is undefined)
sum = 43; (After execution of 2st statement, the data type )
sum=”empty”; (Here the data type changes to string)
Identifiers
Operators
Literals
Punctuations
CS101: Introduction to Computing
Identifiers:
Rules:
All identifiers must begin with alphabets (a-z or A-Z) or underscore “_”.
Subsequent character can be an alphabet (a-z or A-Z) or number (0-9) or
underscore “_”.
JavaScript keywords can’t be used as identifiers.
Example:
Operators:
Assignment Operator ( = )
Num1 = 45;
Address = “University road, Jawad tower, shop # 20”
Arithmetic Operators ( + , - , / , * ,% )
A=5
B=7
(A==B) (A equals B) returns FALSE
(A > B) (A greater than B) returns FALSE
(A < B) (A less than B) returns TRUE
(A != B) ( A not equals B ) returns TRUE
String Operator ( + )
Literals:
Numeric Literals
45, 89.55, -23,67 e-3
String Literals
“bhola” , “continental”
Boolean Literals
TRUE or FALSE
Punctuations:
Punctuation are the marks, such as comma, semicolons and brackets, used in writing
a JavaScript statement.
Conditional Statements:
If statement
If-else statement
Multiple-if statements
Switch statement
if Statement:
CS101: Introduction to Computing
General Syntax:
If (conditional expression)
{Statements ;}
Example:
var A,B;
document.write(A);
document.write(B);
if (A > B)
{window.prompt(“A is greater than B”);}
if-else Statement:
General Syntax:
If (conditional expression)
{Statements ;}
else {statements;}
Example:
If (A==B)
{window.prompt(“A is equal to B”);}
else
{window.prompt(“A is not equal to B”);}
Multiple if Statements:
General Syntax:
If (conditional expression)
{Statements ;}
else if{statements;}
else (statements;}
CS101: Introduction to Computing
Example:
var grade,points;
document.write(grade);
if (grade = “A”) {points = 4;}
else if (grade = “B”) {points = 3;}
else if (grade = “C”) {points = 2;}
else if (grade = “D”) {points = 1;}
else {points = 0;}
window.prompt(points);
Switch Statements:
General Syntax:
switch(expression) {
case n:
code block
break;
case n:
code block
break;
default:
default code block}
Example:
var grade,points;
document.write(grade);
switch(grade) {
case “A”:points=4; break;
case “B”:points=3; break;
case “C”:points=2; break;
case “D”:points=1; break;
default:points=0;}
window.prompt(points);
CS101: Introduction to Computing
Loops:
Loops in JavaScript are used to execute the same block of code a specified number of times
or while a specified condition is true.
Types:
for
while
do-while
for Loop:
General Syntax:
Example:
var x;
for(x=1 ; x >10 ; x=x+1)
{window.prompt(x);}
while Loop:
General Syntax:
while(conditional expression)
{statements;}
Example:
var choice=”y”;
while(choice!=”N” || choice!=”n”)
{document.write(choice);}
CS101: Introduction to Computing
do-while Loop:
General Syntax:
do
{statements;}
while(conditional expression);
Example:
var i=0;
do
{window.prompt(i);
i=i+1;}
while(i<20);
Arrays:
Example:
var fruit[5];
Example:
var student1,student2,student3,student4;
document.write(student1);
document.write(student2);
document.write(student3);
document.write(student4);
window.prompt(student1);
window.prompt(student2);
window.prompt(student3);
window.prompt(student4);
var student[4] ,i ;
for(i=0 ; i<4 ; i=i+1)
{document.write(student[i]);}
for(i=0 ; i<4 ; i=i+1)
{window.prompt(student[i]);}
Unlike many other popular languages, a JavaScript Array can hold elements of multiple data
types, simultaneously
a = new Array( 9 ) ;
b = new Array( 13 ) ;
b[ 0 ] = 23.7 ;
b[ 1 ] = “Bhola Continental Hotel” ;
d = new Array ( 5 ) ;
document.write( d.length ) ;
Array Methods:
CS101: Introduction to Computing
Sort( )
Reverse( )
Sort( ):
Example:
x = new Array ( 4 ) ;
x[ 0 ] = “Waseem” ;
x[ 1 ] = “Waqar” ;
x[ 2 ] = “Saqlain” ;
x[ 3 ] = “Shoaib” ;
x.sort( ) ;
k = k + 1 ) { document.write( x[ k ] + “<BR>” ) ;}
Reverse( ):
Example:
x = new Array ( 4 ) ;
x[ 0 ] = “Waseem” ;
CS101: Introduction to Computing
x[ 1 ] = “Waqar” ;
x[ 2 ] = “Saqlain” ;
x[ 3 ] = “Shoaib” ;
x.reverse( ) ;
x.sort( ) ;
Program:
CS101: Introduction to Computing
Function:
A group of statements that is put together (or defined) once and then can be used (by
reference) repeatedly on a Web page .Also known as subprogram, procedure, subroutine.
Example:
Advantages of Functions
Example:
Function Identifiers:
The naming rules for function identifiers are the same as were discussed for variable and array
identifiers
Arguments of a Function :
A comma-separated list of data Arguments define the interface between the function and the
rest of the Web page Arguments values are passed to the function by value (some popular
languages pass arguments ‘by reference’ as well).
CS101: Introduction to Computing
Methods :
Methods are functions They are unusual in the sense that they are stored as properties of
objects
Object:
parseInt( ),
parseFloat( )
CS101: Introduction to Computing
parseInt( ):
Example:
parseFloat( ):
Scope of Variable :
Defining the space in which a variable is effective is known as defining the scope of a
variable. A variable can be either local or global in scope.
Local Variables :
Local or Function-level Variable Effective only in the function in which they are declared
CS101: Introduction to Computing
Global Variables: