SlideShare a Scribd company logo
Course Code: CSE 202
Course Title: Computer Programming Lab
Lecture 3: Operators in JS
Course Teacher: Saurav Barua (SB)
Assistant Professor, Dept. of CE, DIU
Phone: +88-01715334075
Email: saurav.ce@diu.edu.bd
Contents
2
Logical
operators
Arithmetic
operator
Assignment
operator
Comparison
operator
Types of
operators
.
Ternary operator
Types of operators
3
There are different types of JavaScript operators:
1. Arithmetic Operators
2. Assignment Operators
3. Comparison Operators
4. String Operators
5. Logical Operators
6. Bitwise Operators
7. Ternary Operators
8. Type Operators
Arithmetic operator
4
Operator Description
+ Addition
- Subtraction
* Multiplication
** Exponentiation (ES2016)
/ Division
% Modulus (Division Remainder)
++ Increment
-- Decrement
Arithmetic operator
5
 i++ stands for i= i+1
 % stands for reminder. Example: 6%4 = 2.
Assignment operator
6
Operator Example Same As
= x = y x = y
+= x += y x = x + y
-= x -= y x = x - y
*= x *= y x = x * y
/= x /= y x = x / y
%= x %= y x = x % y
**= x **= y x = x ** y
Comparison operator
7
Operator Description
== equal to
=== equal value and equal type
!= not equal
!== not equal value or not equal type
> greater than
< less than
>= greater than or equal to
<= less than or equal to
? ternary operator
Comparison operator
8
 20==“20”. //output: True. == only check value.
 20===“20”. //output: False. === check value and data type.
Syntax for ternary operator:
condition ? exprIfTrue : exprIfFalse
Example:
const age = 26;
const beverage = age >= 5 ? “Coke" : "Juice";
console.log(beverage); // output: Coke
Syntax:
variablename = (condition) ? value1:value2
Example: let voteable = (age < 18) ? "Too young":"Old enough";
Logical operator
9
Operator Description Example
&& and (x < 10 && y > 1) is true
|| or (x == 5 || y == 5) is false
! not !(x == y) is true
logical operator
10
Logical operator only return true (1) or false (0).
 Evaluate: (2<3)&&(4>2||3<2)
 Evaluate: (!1&&2>=3)||(3<4)
Worked out example
11
Example 3: Program to take input from prompt and calculate through JS and
display in the browser. (Calculate area of a triangle, take length and height as an
input through prompt and display in the browser.)
Google drive link:
https://drive.google.com/drive/folders/1DNqm-
2rFkuRJXg5Cb6PMa9fgd82mE-pD?usp=drive_link
Git-hub link: https://github.com/sauravbarua02/triangleAreaCalculation
Interface
12
html codes
13
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, initial-
scale=1.0">
<title>LogicControl</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="container"
id="container">
<div id="result"></div>
<script src="app.js"></script>
</div>
</body>
</html>
css codes
14
body{
margin: 0px;
background-color: rgba(90,90,230,0.6);
}
.container{
background-color: rgba(90,90,230,0.3);
width: 300px;
height: 300px;
margin: 20px auto;
padding: 10px;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
border-radius: 10px;
box-shadow: 0 0 3px 1px rgba(0,0,0,0.5);
font-size: large;
}
JS codes
15
const resultEl =
document.getElementById("result");
const length = prompt("Enter length in meter
= ");
const height = prompt("Enter height in meter
= ");
function areaCal(){
const area = 0.5*length*height;
resultEl.innerText = "Area of the
triangle: " + area + " sq. meter";
}
areaCal();
Class tasks
16
Task 3.1: Program to calculate average penetration in mm from three bitumen
samples in the bitumen penetration test. Take penetration values as input and
display average value in the browser. (hints: average = (val1 + val2 +val3)/3)
Task 3.2: Program to calculate area of a rectangular industrial plot. Take width and
breadth as input and display area (sq. ft) in the browser. (hints: areaRectangle = width x
breadth)
Task 3.3: Program to calculate discharge of an irrigation canal. Take cross-section and
water velocity as input and display discharge (cum/sec) in the browser. (hints:
discharge= crossSection x velocity)
Task 3.4: Program to calculate delay in a signalized intersection. Take travel time and
free flow travel time as input and display delay (sec) in the browser.(hints: delay =
travelTime – freeFlowTravelTime)
Task 3.5: Program to calculate maximum bending moment of a simply supported
beam under UDL . Take UDL and span length as input and display moment (kip-ft) in
the browser.(hints: maxMoment = 1/8 x UDL x span x span)
End of the Lecture
17

More Related Content

Similar to L3. Operators in JS, CSE 202, BN11.pdf JavaScript (20)

PPTX
Operator 04 (js)
AbhishekMondal42
 
PDF
Javascript breakdown-workbook
HP IT GROUP (TEBIM TEBITAGEM) TTGRT HP E-TİCARET
 
PPTX
Chapter 1 .pptx
MohamedAbdullahiYusu
 
PPS
CS101- Introduction to Computing- Lecture 35
Bilal Ahmed
 
PDF
JavaScript - Chapter 5 - Operators
WebStackAcademy
 
DOC
Java script questions
Srikanth
 
PPTX
JavaScript, VBScript, AJAX, CGI
Aashish Jain
 
PDF
Ch. 17 FIT5, CIS 110 13F
mh-108
 
PPTX
Performing calculations using java script
Jesus Obenita Jr.
 
PDF
javascript-variablesanddatatypes-130218094831-phpapp01.pdf
AlexShon3
 
PPT
Fundamentals of Programming Chapter 5
Mohd Harris Ahmad Jaal
 
PPTX
Introduction to Client-Side Javascript
Julie Iskander
 
PPTX
JavaScript Session 2
Muhammad Ehtisham Siddiqui
 
PPTX
Java script session 4
Saif Ullah Dar
 
PPSX
DIWE - Programming with JavaScript
Rasan Samarasinghe
 
PPT
data-types-operators-datatypes-operators.ppt
Gagan Rana
 
PPTX
Python notes for students to develop and learn
kavithaadhilakshmi
 
PDF
Google maps
Muhammed M Bassem
 
PPTX
Operator in c programming
Manoj Tyagi
 
PPT
object oriented programming java lectures
MSohaib24
 
Operator 04 (js)
AbhishekMondal42
 
Chapter 1 .pptx
MohamedAbdullahiYusu
 
CS101- Introduction to Computing- Lecture 35
Bilal Ahmed
 
JavaScript - Chapter 5 - Operators
WebStackAcademy
 
Java script questions
Srikanth
 
JavaScript, VBScript, AJAX, CGI
Aashish Jain
 
Ch. 17 FIT5, CIS 110 13F
mh-108
 
Performing calculations using java script
Jesus Obenita Jr.
 
javascript-variablesanddatatypes-130218094831-phpapp01.pdf
AlexShon3
 
Fundamentals of Programming Chapter 5
Mohd Harris Ahmad Jaal
 
Introduction to Client-Side Javascript
Julie Iskander
 
JavaScript Session 2
Muhammad Ehtisham Siddiqui
 
Java script session 4
Saif Ullah Dar
 
DIWE - Programming with JavaScript
Rasan Samarasinghe
 
data-types-operators-datatypes-operators.ppt
Gagan Rana
 
Python notes for students to develop and learn
kavithaadhilakshmi
 
Google maps
Muhammed M Bassem
 
Operator in c programming
Manoj Tyagi
 
object oriented programming java lectures
MSohaib24
 

More from SauravBarua11 (20)

PDF
L11, Project Survey , Spring 24, lecture notes, SB.pdf
SauravBarua11
 
PDF
L5, Computation of Area, Spring 24, SB.pdf
SauravBarua11
 
PDF
L4, Contour, Spring 24, lecture notes, SB.pdf
SauravBarua11
 
PDF
L3, Traverse Survey, Spring 24, lecture notes, SB.pdf
SauravBarua11
 
PDF
L8, Tacheometry survey, Spring 24, SB.pdf
SauravBarua11
 
PDF
L10, Astronomical surveying, Spring 24, SB.pdf
SauravBarua11
 
PDF
L6, Computation of Volume, Spring 24, SB.pdf
SauravBarua11
 
PDF
L9, photogrammetric survey, Spring 24, SB.pdf
SauravBarua11
 
PDF
L2, Level surveying, Spring 24,class notes, SB.pdf
SauravBarua11
 
PDF
Confusion matrix in Transportation Engineering.pdf
SauravBarua11
 
PDF
Ordinary least square (OLS) and MLE in Transportation Engineering.pdf
SauravBarua11
 
PDF
L5, Loop and iteration, CSE 202, BN11.pdf
SauravBarua11
 
PDF
L2. Function in JS, CSE 202, BN11.p1df documents
SauravBarua11
 
PDF
L6, Array in JS, CSE 202, BN11.pdf JavaScript
SauravBarua11
 
PDF
L4, Conditional statement, CSE 202 JavaScript
SauravBarua11
 
PDF
L1. Introduction, CSE 202, BN11.pdf JavaScript
SauravBarua11
 
PDF
L7. Object in JS, CSE 202, BN11.pdf JavaScript
SauravBarua11
 
PDF
L9. Math object in JS, CSE 202, BN11.pdf
SauravBarua11
 
PDF
L10. Math.random method in JS, CSE 202, BN11.pdf
SauravBarua11
 
PDF
L8. Constructor and method in JS, CSE 202, BN11.pdf
SauravBarua11
 
L11, Project Survey , Spring 24, lecture notes, SB.pdf
SauravBarua11
 
L5, Computation of Area, Spring 24, SB.pdf
SauravBarua11
 
L4, Contour, Spring 24, lecture notes, SB.pdf
SauravBarua11
 
L3, Traverse Survey, Spring 24, lecture notes, SB.pdf
SauravBarua11
 
L8, Tacheometry survey, Spring 24, SB.pdf
SauravBarua11
 
L10, Astronomical surveying, Spring 24, SB.pdf
SauravBarua11
 
L6, Computation of Volume, Spring 24, SB.pdf
SauravBarua11
 
L9, photogrammetric survey, Spring 24, SB.pdf
SauravBarua11
 
L2, Level surveying, Spring 24,class notes, SB.pdf
SauravBarua11
 
Confusion matrix in Transportation Engineering.pdf
SauravBarua11
 
Ordinary least square (OLS) and MLE in Transportation Engineering.pdf
SauravBarua11
 
L5, Loop and iteration, CSE 202, BN11.pdf
SauravBarua11
 
L2. Function in JS, CSE 202, BN11.p1df documents
SauravBarua11
 
L6, Array in JS, CSE 202, BN11.pdf JavaScript
SauravBarua11
 
L4, Conditional statement, CSE 202 JavaScript
SauravBarua11
 
L1. Introduction, CSE 202, BN11.pdf JavaScript
SauravBarua11
 
L7. Object in JS, CSE 202, BN11.pdf JavaScript
SauravBarua11
 
L9. Math object in JS, CSE 202, BN11.pdf
SauravBarua11
 
L10. Math.random method in JS, CSE 202, BN11.pdf
SauravBarua11
 
L8. Constructor and method in JS, CSE 202, BN11.pdf
SauravBarua11
 
Ad

Recently uploaded (20)

PPT
SF 9_Unit 1.ppt software engineering ppt
AmarrKannthh
 
PPTX
Comparison of Flexible and Rigid Pavements in Bangladesh
Arifur Rahman
 
PPTX
Introduction to File Transfer Protocol with commands in FTP
BeulahS2
 
PDF
Rapid Prototyping for XR: Lecture 3 - Video and Paper Prototyping
Mark Billinghurst
 
PDF
Python Mini Project: Command-Line Quiz Game for School/College Students
MPREETHI7
 
PDF
How to Buy Verified CashApp Accounts IN 2025
Buy Verified CashApp Accounts
 
PPTX
MATERIAL SCIENCE LECTURE NOTES FOR DIPLOMA STUDENTS
SAMEER VISHWAKARMA
 
PPTX
Work at Height training for workers .pptx
cecos12
 
PDF
Rapid Prototyping for XR: Lecture 5 - Cross Platform Development
Mark Billinghurst
 
PPSX
OOPS Concepts in Python and Exception Handling
Dr. A. B. Shinde
 
PDF
May 2025: Top 10 Read Articles in Data Mining & Knowledge Management Process
IJDKP
 
PDF
Validating a Citizen Observatories enabling Platform by completing a Citizen ...
Diego López-de-Ipiña González-de-Artaza
 
PPTX
CST413 KTU S7 CSE Machine Learning Clustering K Means Hierarchical Agglomerat...
resming1
 
PDF
lesson4-occupationalsafetyandhealthohsstandards-240812020130-1a7246d0.pdf
arvingallosa3
 
PDF
13th International Conference of Security, Privacy and Trust Management (SPTM...
ijcisjournal
 
PPTX
Stability of IBR Dominated Grids - IEEE PEDG 2025 - short.pptx
ssuser307730
 
PDF
تقرير عن التحليل الديناميكي لتدفق الهواء حول جناح.pdf
محمد قصص فتوتة
 
PDF
Rapid Prototyping for XR: Lecture 1 Introduction to Prototyping
Mark Billinghurst
 
PPTX
FSE_LLM4SE1_A Tool for In-depth Analysis of Code Execution Reasoning of Large...
cl144
 
PPT
دراسة حاله لقرية تقع في جنوب غرب السودان
محمد قصص فتوتة
 
SF 9_Unit 1.ppt software engineering ppt
AmarrKannthh
 
Comparison of Flexible and Rigid Pavements in Bangladesh
Arifur Rahman
 
Introduction to File Transfer Protocol with commands in FTP
BeulahS2
 
Rapid Prototyping for XR: Lecture 3 - Video and Paper Prototyping
Mark Billinghurst
 
Python Mini Project: Command-Line Quiz Game for School/College Students
MPREETHI7
 
How to Buy Verified CashApp Accounts IN 2025
Buy Verified CashApp Accounts
 
MATERIAL SCIENCE LECTURE NOTES FOR DIPLOMA STUDENTS
SAMEER VISHWAKARMA
 
Work at Height training for workers .pptx
cecos12
 
Rapid Prototyping for XR: Lecture 5 - Cross Platform Development
Mark Billinghurst
 
OOPS Concepts in Python and Exception Handling
Dr. A. B. Shinde
 
May 2025: Top 10 Read Articles in Data Mining & Knowledge Management Process
IJDKP
 
Validating a Citizen Observatories enabling Platform by completing a Citizen ...
Diego López-de-Ipiña González-de-Artaza
 
CST413 KTU S7 CSE Machine Learning Clustering K Means Hierarchical Agglomerat...
resming1
 
lesson4-occupationalsafetyandhealthohsstandards-240812020130-1a7246d0.pdf
arvingallosa3
 
13th International Conference of Security, Privacy and Trust Management (SPTM...
ijcisjournal
 
Stability of IBR Dominated Grids - IEEE PEDG 2025 - short.pptx
ssuser307730
 
تقرير عن التحليل الديناميكي لتدفق الهواء حول جناح.pdf
محمد قصص فتوتة
 
Rapid Prototyping for XR: Lecture 1 Introduction to Prototyping
Mark Billinghurst
 
FSE_LLM4SE1_A Tool for In-depth Analysis of Code Execution Reasoning of Large...
cl144
 
دراسة حاله لقرية تقع في جنوب غرب السودان
محمد قصص فتوتة
 
Ad

L3. Operators in JS, CSE 202, BN11.pdf JavaScript

  • 1. Course Code: CSE 202 Course Title: Computer Programming Lab Lecture 3: Operators in JS Course Teacher: Saurav Barua (SB) Assistant Professor, Dept. of CE, DIU Phone: +88-01715334075 Email: [email protected]
  • 3. Types of operators 3 There are different types of JavaScript operators: 1. Arithmetic Operators 2. Assignment Operators 3. Comparison Operators 4. String Operators 5. Logical Operators 6. Bitwise Operators 7. Ternary Operators 8. Type Operators
  • 4. Arithmetic operator 4 Operator Description + Addition - Subtraction * Multiplication ** Exponentiation (ES2016) / Division % Modulus (Division Remainder) ++ Increment -- Decrement
  • 5. Arithmetic operator 5  i++ stands for i= i+1  % stands for reminder. Example: 6%4 = 2.
  • 6. Assignment operator 6 Operator Example Same As = x = y x = y += x += y x = x + y -= x -= y x = x - y *= x *= y x = x * y /= x /= y x = x / y %= x %= y x = x % y **= x **= y x = x ** y
  • 7. Comparison operator 7 Operator Description == equal to === equal value and equal type != not equal !== not equal value or not equal type > greater than < less than >= greater than or equal to <= less than or equal to ? ternary operator
  • 8. Comparison operator 8  20==“20”. //output: True. == only check value.  20===“20”. //output: False. === check value and data type. Syntax for ternary operator: condition ? exprIfTrue : exprIfFalse Example: const age = 26; const beverage = age >= 5 ? “Coke" : "Juice"; console.log(beverage); // output: Coke Syntax: variablename = (condition) ? value1:value2 Example: let voteable = (age < 18) ? "Too young":"Old enough";
  • 9. Logical operator 9 Operator Description Example && and (x < 10 && y > 1) is true || or (x == 5 || y == 5) is false ! not !(x == y) is true
  • 10. logical operator 10 Logical operator only return true (1) or false (0).  Evaluate: (2<3)&&(4>2||3<2)  Evaluate: (!1&&2>=3)||(3<4)
  • 11. Worked out example 11 Example 3: Program to take input from prompt and calculate through JS and display in the browser. (Calculate area of a triangle, take length and height as an input through prompt and display in the browser.) Google drive link: https://drive.google.com/drive/folders/1DNqm- 2rFkuRJXg5Cb6PMa9fgd82mE-pD?usp=drive_link Git-hub link: https://github.com/sauravbarua02/triangleAreaCalculation
  • 13. html codes 13 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial- scale=1.0"> <title>LogicControl</title> <link rel="stylesheet" href="style.css"> </head> <body> <div class="container" id="container"> <div id="result"></div> <script src="app.js"></script> </div> </body> </html>
  • 14. css codes 14 body{ margin: 0px; background-color: rgba(90,90,230,0.6); } .container{ background-color: rgba(90,90,230,0.3); width: 300px; height: 300px; margin: 20px auto; padding: 10px; display: flex; flex-direction: column; justify-content: center; align-items: center; border-radius: 10px; box-shadow: 0 0 3px 1px rgba(0,0,0,0.5); font-size: large; }
  • 15. JS codes 15 const resultEl = document.getElementById("result"); const length = prompt("Enter length in meter = "); const height = prompt("Enter height in meter = "); function areaCal(){ const area = 0.5*length*height; resultEl.innerText = "Area of the triangle: " + area + " sq. meter"; } areaCal();
  • 16. Class tasks 16 Task 3.1: Program to calculate average penetration in mm from three bitumen samples in the bitumen penetration test. Take penetration values as input and display average value in the browser. (hints: average = (val1 + val2 +val3)/3) Task 3.2: Program to calculate area of a rectangular industrial plot. Take width and breadth as input and display area (sq. ft) in the browser. (hints: areaRectangle = width x breadth) Task 3.3: Program to calculate discharge of an irrigation canal. Take cross-section and water velocity as input and display discharge (cum/sec) in the browser. (hints: discharge= crossSection x velocity) Task 3.4: Program to calculate delay in a signalized intersection. Take travel time and free flow travel time as input and display delay (sec) in the browser.(hints: delay = travelTime – freeFlowTravelTime) Task 3.5: Program to calculate maximum bending moment of a simply supported beam under UDL . Take UDL and span length as input and display moment (kip-ft) in the browser.(hints: maxMoment = 1/8 x UDL x span x span)
  • 17. End of the Lecture 17