0% found this document useful (0 votes)
3 views

Computer Hand Out Half Yearly

The document is a comprehensive handout for Grade 8 Computer Science at Delhi Public School Rajnagar Ghaziabad, covering the definition, advantages, and disadvantages of computers, their history, components, types, and the role of software. It also introduces Artificial Intelligence (AI), its goals, advantages, disadvantages, and applications across various fields such as healthcare, finance, and education. The handout serves as an educational resource to understand the fundamentals of computers and AI technology.

Uploaded by

paruldhingra2024
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Computer Hand Out Half Yearly

The document is a comprehensive handout for Grade 8 Computer Science at Delhi Public School Rajnagar Ghaziabad, covering the definition, advantages, and disadvantages of computers, their history, components, types, and the role of software. It also introduces Artificial Intelligence (AI), its goals, advantages, disadvantages, and applications across various fields such as healthcare, finance, and education. The handout serves as an educational resource to understand the fundamentals of computers and AI technology.

Uploaded by

paruldhingra2024
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

DELHI PUBLIC SCHOOL RAJNAGAR GHAZIABAD

(Under the aegis of The Delhi Public School Society, East of Kailash, New Delhi)
Computer Science Half Yearly Handout(2023-24)
Grade 8
---------------------------------------------------------------------------------------------------------
Introduction:
Computers are everywhere! From office desks to kitchen tables, from library tables to people’s laps in coffee
shops. Computer is an electronic device for performing arithmetic and logical operations.

What is a Computer?
Computer is an electronic device that processes data and converts it into information So that it
becomes useful to people. Computers have changed the way we work, communicate, create and play.
Advantages of Computers
1. Speed: A computer is a very fast device capable of performing calculations on a very large amount of
data. It can perform millions of calculations in a few seconds.
2. Accuracy: Computers are very accurate. They perform all jobs with 100% accuracy provided that the input is
correct.
3. Storage Capacity: A computer has much more storage capacity than human beings. It can store any
type of data such as images, videos, text, audio, etc.
4. Diligence: Unlike human beings, computer is free from monotony, tired less and lack of concentration.
It can work continuously without any errors and boredom.
Disadvantages of Computers
1. No I.Q.: A computer cannot take any decision on its own. A computer cannot see or think of any
specific action as per the corresponding situation.
2. No feeling: Computers have no feelings or emotions. Unlike human beings’ computer cannot make
Judgment based on feeling, taste, experience, and knowledge.

History of Computer:
Since the evolution of humans, devices have been used for calculations for thousands of years. One of the
earliest and most well-known devices was an abacus. Then in 1822, the father of computers, Charles
Babbage began developing what would be the first mechanical computer. And then in 1833 he designed an
Analytical Engine which was a general- purpose computer. It contained an ALU, some basic flow chart
principles and the concept of integrated memory.

Charles Babbage Analytical Engine


Then more than a century later in the history of computers, we got our first electronic computer for general
purpose. It was the ENIAC, which stands for Electronic Numerical Integrator and Computer.

ENIAC

The inventors of this computer were John W. Mauchly and J.Presper Eckert.
And with time technology developed and the computers got smaller and the processing got faster. We got
our first laptop in 1981 and it was introduced by Adam Osborne and EPSON.

Components of Computer:
A computer system is a combination of hardware and software.
Computer hardware includes the physical parts of a computer, such as a case, Central Processing Unit (CPU),
Random Access Memory (RAM), monitor, mouse, keyboard, computer data storage, graphics card, sound
card, speakers and motherboard.
Let us see the block diagram of a computer to better understand it:

The computer takes the input from the input unit, processes it in the CPU and then produces the output.
Input units:
Input units accept the data from the outside world and convert it into computer-understandable form
i.e., the binary form. For example, keyboard, mouse, microphones, etc.

Output units:
It produces the output in user-understandable form. Examples of output unit are monitor, printer, speakers,
plotters, etc.

Central Processing Unit/Microprocessor:


CPU is called the brain of the computer. It consists of:

1. ALU (Arithmetic and Logical Unit): The ALU performs simple addition, subtraction, multiplication,
division, and logic operations, such as OR and AND. The memory stores the program's instructions and
data.
2. CU (Control Unit): The Control Unit (CU) is a component of the CPU that directs the operation of the
processor. It tells the computer's memory, arithmetic and logic unit and input and output devices how to
respond to the instructions that have been sent to the processor.
3. Registers: They are the internal memory of the computer to store temporary data. A register is
basically a storage space for units of memory that are used to transfer data for immediate use by the CPU
(Central Processing Unit) for data processing.
Memory Unit:
They are used to store data for later reference. There are two types of memory:
1. Primary Memory: Primary memory is the internal memory of the computer i.e., the RAM (Random
Access Memory) and the ROM (Read Only Memory). RAM is a temporary memory while ROM is a
permanent memory.
2. Secondary Memory: External memory devices used for the storage of information constitute secondary
memory. For example, hard disk, floppy disk, CD, DVD, Pen Drive, etc.
Types of Computers:
Computers are of various types and they can be categorized in two ways: first on the basis of size and
second on the basis of data handling capabilities.
So, based on size, there are five types of computers:
1. Supercomputer
2. Mainframe computer
3. Minicomputer
4. Workstation
5. PC (Personal Computer)
And on the basis of data handling capabilities, there are three types of computer:
1. Analogue Computer
2. Digital Computer
3. Hybrid Computer
1. Supercomputer: When we talk about speed, then the first name that comes to mind when thinking of
computers is supercomputers. They are the biggest and fastest computers (in terms of speed of processing
data). Supercomputers are designed such that they can process a huge amount of data, like processing
trillions of instructions or data just in a second. This is because of the thousands of interconnected
processors in supercomputers. It is basically used in scientific and engineering applications such as weather
forecasting, scientific simulations, and nuclear energy research. It was first developed by Roger Cray in 1976.
Characteristics of supercomputers:
• Supercomputers are the computers that are the fastest and they are also very expensive.
• It can calculate up to ten trillion individual calculations per second, this is also the reason which makes it even
faster.
• It is used in the stock market or big organizations for managing the online currency world such as Bitcoin etc.
• It is used in scientific research areas for analyzing data obtained from exploring the solar system, satellites,
etc.
2. Mainframe computer: Mainframe computers are designed in such a way that it can support hundreds or
thousands of users at the same time. It also supports multiple programs simultaneously. So, they can
execute different processes simultaneously. All these features make the mainframe computer ideal for big
organizations like banking, telecom sectors, railways, and airports, etc., which process a high volume of
data in general.
Characteristics of mainframe computers:
• It is an expensive or costly computer.
• It has high storage capacity and great performance.
• It can process a huge amount of data (like data involved in the banking sector) very quickly.
• It runs smoothly for a long time and has a long life.
3. Minicomputer: Minicomputer is a medium size multiprocessing computer. In this type of computer,
there are two or more processors, and it supports 4 to 200 users at one time. Minicomputers are used in
places like institutes or departments for different work like billing, accounting, inventory management etc.
It is smaller than a mainframe computer but larger in comparison to the microcomputer.
Characteristics of a minicomputer:
• Its weight is low.
• Because of its low weight, it is easy to carry anywhere.
• Less expensive than a mainframe computer.
• It is fast.
4. Workstation: A workstation is designed for technical or scientific applications. It consists of a fast
microprocessor, with a large amount of RAM and a high-speed graphic adapter. It is a single-user
computer. It is generally used to perform a specific task with great accuracy.
Characteristics of Workstation:
• It is expensive or high in cost.
• They are exclusively made for complex work purposes.
• It provides large storage capacity, with better graphics, and a more powerful CPU when compared to a PC.
• It is also used to handle animation, data analysis, CAD, audio and video creation, and editing.
5. PC (Personal Computer): It is also known as a microcomputer. It is basically a general-purpose computer and
designed for individual use. It consists of a microprocessor as a central processing unit (CPU), memory, input
unit, and output unit. This kind of computer is suitable for personal work such as making an assignment,
watching a movie, or at the office for office work, etc. For example, Laptops and desktop computers.
Characteristics of PC (Personal Computer):
• In this limited number of software can be used.
• It is smallest in size.
• It is designed for personal use.
• It is easy to use.
6. Analogue Computer: It is particularly designed to process analogue data. Continuous data that
changes continuously and cannot have discrete values is called analogue data. So, an analogue computer
is used where we don’t need exact values or need approximate values such as speed, temperature,
pressure etc. It can directly accept the data from the measuring device without first converting it into
numbers and codes. It measures the continuous changes in physical quantity. It gives output as a reading
on a dial or scale. For example, speedometer, mercury thermometer, etc.
7. Digital Computer: Digital computers are designed in such a way that it can easily perform calculations
and logical operations at high speed. It takes raw data as an input and processes it with programs stored in
its memory to produce the final output. It only understands the binary input 0 and 1, so the raw input data
is converted to 0 and 1 by the computer and then it is processed by the computer to produce the result or
final output. All modern computers, like laptops, desktops including smartphones are digital computers.
8. Hybrid Computer:
As the name suggests hybrid, which means made by combining two different things. Similarly, the hybrid
computer is a combination of both analog and digital computers. Hybrid computers are fast like an analog
computer and have memory, and accuracy like a digital computer. So, it has the ability to process both
continuous and discrete data. For working when it accepts analog signals as input then it converts them into
digital form before processing the input data. So, it is widely used in specialized applications where both
analog and digital data is required to be processed. A processor which is used in petrol pumps that converts
the measurements of fuel flow into quantity and price is an example of a hybrid computer.

Software:
A software is a program or application that tells the computer what to do and how to perform a specific
task. There are two types of software:
1. Application software
They are the software that works with the operating system to help the computer perform a specific type
of work. For example, word processors, spreadsheets, database programs, Photoshop, etc.
2. System software
They direct all the activities and sets all for how the hardware and the software will work together. For
example, Windows, Linux, Mac, Android, etc. are some of the operating system software.

What is Artificial Intelligence (AI)?


Artificial Intelligence is composed of two words Artificial and Intelligence, where
Artificial defines "man-made," and intelligence defines "thinking power", hence AI
means "a man-made thinking power."
So, we can define AI as:
"It is a branch of computer science by which we can create intelligent machines which can behave like
human, think like human and then able to make decisions."
Artificial Intelligence exists when a machine can have human-based skills such as learning, reasoning, and
solving problems.
With Artificial Intelligence you do not need to pre-program a machine to do some work, despite that you can
create a machine with programmed algorithms that can work with own intelligence, and that is the
awesomeness of AI.

Goals of Artificial Intelligence:


The overall goal would be to allow machines and computers to learn and function intelligently. Some of the
other goals of AI are as follows:
1. Problem-solving: Researchers developed algorithms that were able to imitate the step-by-step process
that humans use while solving a puzzle. The search for efficient problem-solving algorithms is one of the
goals of artificial intelligence.
2. Knowledge representation: Machines are expected to solve problems that require extensive
knowledge. Artificial intelligence represents objects, properties, events, cause and effect, and much more.
3. Planning: One of the goals of AI should be to set intelligent goals and achieve them. Being able to make
predictions about how actions will impact change, and what are the choices available.
4. Learning: One of the fundamental concepts of AI, machine learning, is the study of computer
algorithms that continue to improve over time through experience.
5. Social Intelligence: Affective computing is essentially the study of systems that can interpret,
recognize, and process human efforts. It is a confluence of computer science, psychology, and
cognitive science.
WHY IS LEARNING ABOUT AI IMPORTANT?
• AI is all around us, people use artificial intelligence every single day.
• This is already true of many professions today.
• Doctors use AI to diagnose patients based on medical scans, like X-rays.
• Astronauts can use AI models to detect exoplanets or planets outside our Solar System.
Advantages of Artificial Intelligence
 Reduction in human error
 Available 24×7
 Helps in repetitive work
 Digital assistance
 Faster decisions
 Rational Decision Maker
 Medical applications
 Improves Security
 Efficient Communication

Disadvantages of Artificial Intelligence


High Costs of Creation
Makes Humans Lazy:
Promotes Unemployment:
No Emotions:
Lacks Out of Box Thinking

1. AI in Astronomy
Artificial Intelligence can be very useful to solve complex universal problems. AI technology can be
helpful for understanding the universe such as how it works, its origin, etc.
2. AI in Healthcare
Healthcare Industries are applying AI to make a better and faster diagnosis than humans. AI can help
doctors with diagnoses and can inform when patients are worsening so that medical help can reach to the
patient before hospitalization.
3. AI in Gaming
AI can be used for gaming purpose. The AI machines can play strategic games like chess, where the machine
needs to think of a large number of possible places.
4. AI in Finance
AI and finance industries are the best matches for each other. The finance industry is implementing
automation, chatbot, adaptive intelligence, algorithm trading, and machine learning into financial
processes.
5. AI in Data Security
The security of data is crucial for every company and cyber-attacks are growing very rapidly in the digital
world. AI can be used to make your data more safe and secure. Some examples such as AEG bot, AI2
Platform, are used to determine software bug and cyber-attacks in a better way.
6. AI in Social Media
Social Media sites such as Facebook, Twitter, and Snapchat contain billions of user profiles, which need to
be stored and managed in a very efficient way. AI can organize and manage massive amounts of data. AI
can analyze lots of data to identify the latest trends, hashtag, and requirement of different users.
7. AI in Travel & Transport
AI is becoming highly demanding for travel industries. AI is capable of doing various travel related works
such as from making travel arrangement to suggesting the hotels, flights, and best routes to the customers.
Travel industries are using AI-powered chatbots which can make human-like interaction with customers for
better and fast response.
8. AI in Automotive Industry
Some Automotive industries are using AI to provide virtual assistant to their user for better performance.
Such as Tesla has introduced Tesla Bot, an intelligent virtual assistant.
Various Industries are currently working for developing self-driven cars which can make your journey
more safe and secure.
9. AI in Robotics:
•Artificial Intelligence has a remarkable role in Robotics. Usually, general robots are programmed such
that they can perform some repetitive tasks, but with the help of AI, we can create intelligent robots
which can perform tasks with their own experiences without pre-programmed.
•Humanoid Robots are best examples for AI in robotics, recently the intelligent Humanoid robot named as
Erica and Sophia has been developed which can talk and behave like humans.
10. AI in Entertainment:
We are currently using some AI based applications in our daily life with some entertainment services such as
Netflix or Amazon. With the help of ML/AI algorithms, these services show the recommendations for programs
or shows.
11. AI in Agriculture:
Agriculture is an area which requires various resources, labor, money, and time for best result. Now a day's
agriculture is becoming digital, and AI is emerging in this field. Agriculture is applying AI as agriculture
robotics, solid and crop monitoring, predictive analysis. AI in agriculture can be very helpful for farmers.
12. AI in E-commerce:
AI is providing a competitive edge to the e-commerce industry, and it is becoming more demanding in the
e-commerce business. AI is helping shoppers to discover associated products with recommended size,
color, or even brand.
13. AI in education:
• AI can automate grading so that the tutor can have more time to teach. AI chatbot can
communicate with students as a teaching assistant.
• AI in the future can be work as a personal virtual tutor for students, which will be accessible easily
at any time and any place.

Introduction to JavaScript
JavaScript is the scripting language of the Web.
JavaScript is the most popular scripting language that works in all major browsers, such as Internet Explorer,
Mozilla Firefox, and Opera.

What is JavaScript?
 JavaScript was designed to add interactivity to HTML pages.
 JavaScript is a scripting language.
 A scripting language is a lightweight programming language.
 JavaScript is usually embedded directly into HTML pages.
 JavaScript is an interpreted language (which means that scripts execute without compilation).
 Everyone can use JavaScript without purchasing a license.

Java and JavaScript are two completely different languages in both concept and design!
Java (developed by Sun Microsystems) is a powerful and much more complex programming language – in the
same category as C and C++.

What can JavaScript Do?


 JavaScript gives HTML designers a programming tool - HTML authors are normally not
programmers, but JavaScript is a scripting language with a very simple syntax! Almost anyone
canput small "snippets" of code into their HTML pages
 JavaScript can put dynamic text into an HTML page - A JavaScript statement like
this: document.write("<h1>" + name + "</h1>") can write a variable text into an
HTML page
 JavaScript can react to events - A JavaScript can be set to execute when something
happens,like when a page has finished loading or when a user clicks on an HTML element
 JavaScript can read and write HTML elements - A JavaScript can read and change the
contentof an HTML element
 JavaScript can be used to validate data - A JavaScript can be used to validate form data
beforeit is submitted to a server. This saves the server from extra processing
 JavaScript can be used to detect the visitor's browser - A JavaScript can be used to detect the
visitor's browser, and - depending on the browser - load another page specifically designed for
that browser.
 JavaScript can be used to create cookies - A JavaScript can be used to store and
retrieve information on the visitor's computer.

JavaScript Variables:
Variables are "containers" for storing information. JavaScript variables are used to hold values or expressions.
A variable can have a short name, like x, or a more descriptive name, like carname.Rules for JavaScript
variable names:
 Variable names are case sensitive (y and Y are two different variables)
 Variable names must begin with a letter or the underscore character.
Note: Because JavaScript is case-sensitive, variable names are case-sensitive.
Example: A variable's value can change during the execution of a script. You can refer to a variable by its
name to display or change its value.
<html>
<body>
<script type="text/javascript">
var firstname;
firstname="Welcome";
document.write(firstname);
document.write("<br />");
firstname="XYZ";
document.write(firstname);
</script>
<p>The script above declares a variable,
assigns a value to it, displays the value, change the value,and displays the value again.</p>
</body>
</html>

Output:

Welcome
XYZ
The script above declares a variable, assigns a value to it, displays the value, changes the value, anddisplays
the value again.

Declaring (Creating) JavaScript Variables:

Creating variables in JavaScript is most often referred to as "declaring" variables.You


can declare JavaScript variables with the var statement:
var x;
var carname;

After the declaration shown above, the variables are empty (they have no values yet).However,
you can also assign values to the variables when you declare them:
var x=5;
var carname="Scorpio";

After the execution of the statements above, the variable x will hold the value 5, and carname will holdthe value
Scorpio.
Note: When you assign a text value to a variable, use quotes around the value.

Assigning Values to Undeclared JavaScript Variables

If you assign values to variables that have not yet been declared, the variables will automatically

bedeclared. These statements:

x=5;
carname="Scorpio";

have the same effect as:

var x=5;
var carname="Scorpio";

Redeclaring JavaScript Variables

If you redeclare a JavaScript variable, it will not lose its original value.

var x=5;
var x;

After the execution of the statements above, the variable x will still have the value of 5. The value of x isnot
reset (or cleared) when you redeclare it.
DataTypes:

 Numbers - are values that can be processed and calculated. You don't enclose them in
quotation marks. The numbers can be either positive or negative.
 Strings - are a series of letters and numbers enclosed in quotation marks. JavaScript uses the
string literally; it doesn't process it. You'll use strings for text you want to be displayed or values
you want to be passed along.
 Boolean (true/false) - lets you evaluate whether a condition meets or does not meet specifiedcriteria.
 Null - is an empty value. null is not the same as 0 -- 0 is a real, calculable number, whereas null is the
absence of any value.

Data Types

TYPE EXAMPLE
Numbers Any number, such as 17, 21, or 54e7
Strings "Greetings!" or "Fun"
Boolean Either true or false
Null A special keyword for exactly that – the null value (that is, nothing)

JavaScript Arithmetic

As we use operators in algebra in- same way arithmetic operators are used in JavaScript.
y=x-5;
z=y+5;

JavaScript Operators
 The operator = is used to assign values.
 The operator + is used to add values.
 The assignment operator = is used to assign values to JavaScript variables.
 The arithmetic operator + is used to add values together.
y=5;
z=2;
x=y+z;
The value of x, after the execution of the statements above is 7.

JavaScript Arithmetic Operators

Arithmetic operators are used to perform arithmetic between variables and/or values. Given that y=5, the

table below explains the arithmetic operators:

Operato Description Example Result


r
+ Addition x=y+2 x=7
- Subtraction x=y-2 x=3
* Multiplication x=y*2 x=10
/ Division x=y/2 x=2.5
% Modulus (division remainder) x=y%2 x=1
++ Increment x=++y x=6
-- Decrement x=--y x=4

JavaScript Assignment Operators


Assignment operators are used to assign values to JavaScript variables. Given that x=10 and y=5, the table below
explains the assignment operators:

Operato Example Same As Result


r
= x=y x=5
+= x+=y x=x+y x=15
-= x-=y x=x-y x=5
*= x*=y x=x*y x=50
/= x/=y x=x/y x=2
%= x%=y x=x%y x=0

The Concatenation Operator (+) Used on Strings

The += assignment operator can also be used to add (concatenate) strings: When used on strings, the +
operator is called the concatenation operator. Adding two numbers will return the sum, but adding a number
and a string will return a string: If you add a number and a string, the result will be a string!

The + operator can also be used to add string variables or text values together. To add two or more string

variables together, use the + operator.

txt1="It’s a ";
txt2="nice day";
txt3=txt1+txt2;
After the execution of the statements above, the variable txt3 contains "It’s a nice day". To add a space

between the two strings, insert a space into one of the strings:

txt1="It’s a ";
txt2="nice day";
txt3=txt1+txt2;

or insert a space into the expression:


txt1="It’s a";
txt2="nice day";
txt3=txt1+" "+txt2;

After the execution of the statements above, the variable txt3 contains: "It’s a nice day"

Adding Strings and Numbers

Look at these examples:

x=5+5;
document.write(x);

x="5"+"5";
document.write(x);

x=5+"5";
document.write(x);

x="5"+5;
document.write(x);

The rule is:

If you add a number and a string, the result will be a string. JavaScript Comparison and Logical Operators Comparison
and Logical operators are used to test for true or false.

Comparison Operators:
Comparison operators are used in logical statements to determine equality or difference between
variables or values. Given that x=5, the table below explains the comparison operators:
Operato Description Example
r
== is equal to x==8 is false
=== is exactly equal to (value and type) x===5 is true
x==="5" is false
!= is not equal x!=8 is true
> is greater than x>8 is false
< is less than x<8 is true
>= is greater than or equal to x>=8 is false
<= is less than or equal to x<=8 is true
How Can it be Used?

Comparison operators can be used in conditional statements to compare values and take action
depending on the result:

if (age<18) document.write("Not eligible to vote");

You will learn more about the use of conditional statements in the next chapter of this tutorial.

Logical Operators
Logical operators are used to determine the logic between variables or values. Given that x=6 and y=3,
the table below explains the logical operators:
Operato Descriptio Example
r n
&& and (x < 10 && y > 1) is true
|| or (x==5 || y==5) is false
! not !(x==y) is true

Conditional Operator or Ternary Operator:


JavaScript also contains a conditional operator that assigns a value to a variable based on some condition.
Syntax
variable_name = (condition)? value1:value2;

Example
result = (age >= 18)? "Can Vote": "Cannot Vote";

If the variable age has a value greater than or equal to 18, then the variable result will be assigned the value "Can
Vote"
else it will be assigned "Cannot Vote".
Sample Programs

Note: - Kindly use Notepad for writing the code and save the file as “filename.html”.

1: Write a program to Print Hello World in JavaScript.


<html>
<body>
<script type="text/javascript">
// the hello world program
document.write('Hello,
World!');
</script>
</body>
</html >

Output:

Hello, World!

2: Write a program to print sum of two Numbers in JavaScript.


<html>
<body>
<script
type="text/javascript"> var
num1 = 5;
var num2 = 3;
// add two numbers
var sum = num1 + num2;
// display the sum
document.write('The sum of ' + num1 + ' and ' + num2 + ' is: ' + sum);
</script>
</body>
</html>

Output:

The sum of 5 and 3 is: 8

3: Write a program in JavaScript to apply arithmetic operators like +, -, *, /, %, ++, --, **.
<html>
<body>
<script
type="text/javascript"> var x
= 5;
var y = 3;

// addition
document.write('x + y = ', x + y+"</br>");

// subtraction
document.write('x - y = ', x - y+"</br>");

// multiplication
document.write('x * y = ', x * y+"</br>");

// division
document.write('x / y = ', x / y+"</br>");

// remainder
document.write('x % y = ', x % y+"</br>");

// increment
document.write('++x = ', ++x+"</br>");
document.write('x++ = ', x+++"</br>");
document.write('x = ', x+"</br>");

// decrement
document.write('--x = ', --x+"</br>");
document.write('x-- = ', x--+"</br>");
document.write('x = ', x+"</br>");

//exponentiation
document.write('x ** y =', x ** y+"</br>");

</script>
</body>
</html>

x+y=8
x-y=2
x * y = 15
x / y = 1.6666666666666667
x%y=2
++x = 6
x++ = 6
x= 7
--x = 6
x-- = 6
x= 5
x ** y = 125

4: Comparison Operators in JavaScript.


<html>
<body>
<script type="text/javascript">

var a = 10;
var b = 5;
document.write("a > b : " ,a > b)
document.write("a < b : " ,a<b);
document.write("a >= b : ",a >= b);
document.write("a <= b : " ,a <= b);
document.write("a == b : ",a == b);
document.write("a != b : ",a != b);
</script>
</body>
</html>

Output

a > b : true
a < b : false
a >= b : true
a <= b : false
a == b : false
a != b : true

5: Logical Operators in JavaScript.


<html>
<body>
<script type="text/javascript">
var x = 6;
var y = 3;
document.write((x < 10 && y > 1)+"</br>");
document.write((x == 5 || y == 5)+"</br>");
document.write(!(x == y)+"</br>");
</script>
</body>
</html>

Output

true
false
true

6: Write a program to find whether a person is eligible to vote or not in JavaScript.


<html>
<body>
<script
type="text/javascript">
age=21;
result = (age >= 18)? "Eligible to vote": " Not eligible to vote";
document.write(result);
</script>
</body>
</html>

Output:

Eligible to vote

7: Write a program to find whether a person is a senior citizen or not in JavaScript.


<html>
<body>
<script
type="text/javascript">
age=33;
result = (age >= 60)? "Senior Citizen": " Not a Senior Citizen";
document.write(result);
</script>
</body>
</html>

Not a Senior Citizen

8: Write a program to calculate the total, average and percentage of five subject’s marks in
JavaScript.
<html>
<body>
<script>
var eng = 75
var comp = 85
var math = 65
var phy = 76
var che = 78
var total = eng + comp + math + phy + che;
var avg = total / 5;
var per = (total / 500) * 100;
document.write("Total Marks ="+total+"</br>");
document.write("Average ="+avg+"</br>");
document.write("Percentage ="+per+" %"+"</br>");
</script>
</body>
</html>

Output:

Total Marks =379


Average =75.8
Percentage =75.8 %

You might also like