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
Ad

More Related Content

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

3306617
33066173306617
3306617
shwetakks
 
Class 2 variables, classes methods...
Class 2   variables, classes methods...Class 2   variables, classes methods...
Class 2 variables, classes methods...
Fernando Loizides
 
C++ project
C++ projectC++ project
C++ project
Sonu S S
 
Spring 2014 CSCI 111 Final exam of 1 61. (2 points) Fl.docx
Spring 2014 CSCI 111 Final exam   of 1 61. (2 points) Fl.docxSpring 2014 CSCI 111 Final exam   of 1 61. (2 points) Fl.docx
Spring 2014 CSCI 111 Final exam of 1 61. (2 points) Fl.docx
rafbolet0
 
Computer paper 3 may june 2004 9691 cambridge General Certificate of educatio...
Computer paper 3 may june 2004 9691 cambridge General Certificate of educatio...Computer paper 3 may june 2004 9691 cambridge General Certificate of educatio...
Computer paper 3 may june 2004 9691 cambridge General Certificate of educatio...
Alpro
 
Java/Scala Lab: Анатолий Кметюк - Scala SubScript: Алгебра для реактивного пр...
Java/Scala Lab: Анатолий Кметюк - Scala SubScript: Алгебра для реактивного пр...Java/Scala Lab: Анатолий Кметюк - Scala SubScript: Алгебра для реактивного пр...
Java/Scala Lab: Анатолий Кметюк - Scala SubScript: Алгебра для реактивного пр...
GeeksLab Odessa
 
Few Operator used in c++
Few Operator used in c++Few Operator used in c++
Few Operator used in c++
sunny khan
 
Dti2143 chapter 3 arithmatic relation-logicalexpression
Dti2143 chapter 3 arithmatic relation-logicalexpressionDti2143 chapter 3 arithmatic relation-logicalexpression
Dti2143 chapter 3 arithmatic relation-logicalexpression
alish sha
 
Operator overloading2
Operator overloading2Operator overloading2
Operator overloading2
zindadili
 
Python Lecture 2
Python Lecture 2Python Lecture 2
Python Lecture 2
Inzamam Baig
 
Tdd for BT E2E test community
Tdd for BT E2E test communityTdd for BT E2E test community
Tdd for BT E2E test community
Kerry Buckley
 
‘How to develop Pythonic coding rather than Python coding – Logic Perspective’
‘How to develop Pythonic coding rather than Python coding – Logic Perspective’‘How to develop Pythonic coding rather than Python coding – Logic Perspective’
‘How to develop Pythonic coding rather than Python coding – Logic Perspective’
S.Mohideen Badhusha
 
operators.ppt
operators.pptoperators.ppt
operators.ppt
SharukSharuk3
 
ch02-primitive-data-definite-loops.ppt
ch02-primitive-data-definite-loops.pptch02-primitive-data-definite-loops.ppt
ch02-primitive-data-definite-loops.ppt
Mahyuddin8
 
ch02-primitive-data-definite-loops.ppt
ch02-primitive-data-definite-loops.pptch02-primitive-data-definite-loops.ppt
ch02-primitive-data-definite-loops.ppt
ghoitsun
 
C lab-programs
C lab-programsC lab-programs
C lab-programs
Tony Kurishingal
 
Visual programming
Visual programmingVisual programming
Visual programming
Dr. C.V. Suresh Babu
 
Cs2312 OOPS LAB MANUAL
Cs2312 OOPS LAB MANUALCs2312 OOPS LAB MANUAL
Cs2312 OOPS LAB MANUAL
Prabhu D
 
05A_Java_in yemen adenProgramming_IT.pptx
05A_Java_in yemen adenProgramming_IT.pptx05A_Java_in yemen adenProgramming_IT.pptx
05A_Java_in yemen adenProgramming_IT.pptx
akrmalslami88
 
CP 04.pptx
CP 04.pptxCP 04.pptx
CP 04.pptx
RehmanRasheed3
 
Class 2 variables, classes methods...
Class 2   variables, classes methods...Class 2   variables, classes methods...
Class 2 variables, classes methods...
Fernando Loizides
 
C++ project
C++ projectC++ project
C++ project
Sonu S S
 
Spring 2014 CSCI 111 Final exam of 1 61. (2 points) Fl.docx
Spring 2014 CSCI 111 Final exam   of 1 61. (2 points) Fl.docxSpring 2014 CSCI 111 Final exam   of 1 61. (2 points) Fl.docx
Spring 2014 CSCI 111 Final exam of 1 61. (2 points) Fl.docx
rafbolet0
 
Computer paper 3 may june 2004 9691 cambridge General Certificate of educatio...
Computer paper 3 may june 2004 9691 cambridge General Certificate of educatio...Computer paper 3 may june 2004 9691 cambridge General Certificate of educatio...
Computer paper 3 may june 2004 9691 cambridge General Certificate of educatio...
Alpro
 
Java/Scala Lab: Анатолий Кметюк - Scala SubScript: Алгебра для реактивного пр...
Java/Scala Lab: Анатолий Кметюк - Scala SubScript: Алгебра для реактивного пр...Java/Scala Lab: Анатолий Кметюк - Scala SubScript: Алгебра для реактивного пр...
Java/Scala Lab: Анатолий Кметюк - Scala SubScript: Алгебра для реактивного пр...
GeeksLab Odessa
 
Few Operator used in c++
Few Operator used in c++Few Operator used in c++
Few Operator used in c++
sunny khan
 
Dti2143 chapter 3 arithmatic relation-logicalexpression
Dti2143 chapter 3 arithmatic relation-logicalexpressionDti2143 chapter 3 arithmatic relation-logicalexpression
Dti2143 chapter 3 arithmatic relation-logicalexpression
alish sha
 
Operator overloading2
Operator overloading2Operator overloading2
Operator overloading2
zindadili
 
Tdd for BT E2E test community
Tdd for BT E2E test communityTdd for BT E2E test community
Tdd for BT E2E test community
Kerry Buckley
 
‘How to develop Pythonic coding rather than Python coding – Logic Perspective’
‘How to develop Pythonic coding rather than Python coding – Logic Perspective’‘How to develop Pythonic coding rather than Python coding – Logic Perspective’
‘How to develop Pythonic coding rather than Python coding – Logic Perspective’
S.Mohideen Badhusha
 
ch02-primitive-data-definite-loops.ppt
ch02-primitive-data-definite-loops.pptch02-primitive-data-definite-loops.ppt
ch02-primitive-data-definite-loops.ppt
Mahyuddin8
 
ch02-primitive-data-definite-loops.ppt
ch02-primitive-data-definite-loops.pptch02-primitive-data-definite-loops.ppt
ch02-primitive-data-definite-loops.ppt
ghoitsun
 
Cs2312 OOPS LAB MANUAL
Cs2312 OOPS LAB MANUALCs2312 OOPS LAB MANUAL
Cs2312 OOPS LAB MANUAL
Prabhu D
 
05A_Java_in yemen adenProgramming_IT.pptx
05A_Java_in yemen adenProgramming_IT.pptx05A_Java_in yemen adenProgramming_IT.pptx
05A_Java_in yemen adenProgramming_IT.pptx
akrmalslami88
 

More from SauravBarua11 (20)

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

Recently uploaded (20)

15th International Conference on Computer Science, Engineering and Applicatio...
15th International Conference on Computer Science, Engineering and Applicatio...15th International Conference on Computer Science, Engineering and Applicatio...
15th International Conference on Computer Science, Engineering and Applicatio...
IJCSES Journal
 
Data Structures_Introduction to algorithms.pptx
Data Structures_Introduction to algorithms.pptxData Structures_Introduction to algorithms.pptx
Data Structures_Introduction to algorithms.pptx
RushaliDeshmukh2
 
Structural Response of Reinforced Self-Compacting Concrete Deep Beam Using Fi...
Structural Response of Reinforced Self-Compacting Concrete Deep Beam Using Fi...Structural Response of Reinforced Self-Compacting Concrete Deep Beam Using Fi...
Structural Response of Reinforced Self-Compacting Concrete Deep Beam Using Fi...
Journal of Soft Computing in Civil Engineering
 
"Feed Water Heaters in Thermal Power Plants: Types, Working, and Efficiency G...
"Feed Water Heaters in Thermal Power Plants: Types, Working, and Efficiency G..."Feed Water Heaters in Thermal Power Plants: Types, Working, and Efficiency G...
"Feed Water Heaters in Thermal Power Plants: Types, Working, and Efficiency G...
Infopitaara
 
The Gaussian Process Modeling Module in UQLab
The Gaussian Process Modeling Module in UQLabThe Gaussian Process Modeling Module in UQLab
The Gaussian Process Modeling Module in UQLab
Journal of Soft Computing in Civil Engineering
 
Artificial Intelligence introduction.pptx
Artificial Intelligence introduction.pptxArtificial Intelligence introduction.pptx
Artificial Intelligence introduction.pptx
DrMarwaElsherif
 
theory-slides-for react for beginners.pptx
theory-slides-for react for beginners.pptxtheory-slides-for react for beginners.pptx
theory-slides-for react for beginners.pptx
sanchezvanessa7896
 
new ppt artificial intelligence historyyy
new ppt artificial intelligence historyyynew ppt artificial intelligence historyyy
new ppt artificial intelligence historyyy
PianoPianist
 
AI-assisted Software Testing (3-hours tutorial)
AI-assisted Software Testing (3-hours tutorial)AI-assisted Software Testing (3-hours tutorial)
AI-assisted Software Testing (3-hours tutorial)
Vəhid Gəruslu
 
Smart Storage Solutions.pptx for production engineering
Smart Storage Solutions.pptx for production engineeringSmart Storage Solutions.pptx for production engineering
Smart Storage Solutions.pptx for production engineering
rushikeshnavghare94
 
Smart_Storage_Systems_Production_Engineering.pptx
Smart_Storage_Systems_Production_Engineering.pptxSmart_Storage_Systems_Production_Engineering.pptx
Smart_Storage_Systems_Production_Engineering.pptx
rushikeshnavghare94
 
Degree_of_Automation.pdf for Instrumentation and industrial specialist
Degree_of_Automation.pdf for  Instrumentation  and industrial specialistDegree_of_Automation.pdf for  Instrumentation  and industrial specialist
Degree_of_Automation.pdf for Instrumentation and industrial specialist
shreyabhosale19
 
lecture5.pptxJHKGJFHDGTFGYIUOIUIPIOIPUOHIYGUYFGIH
lecture5.pptxJHKGJFHDGTFGYIUOIUIPIOIPUOHIYGUYFGIHlecture5.pptxJHKGJFHDGTFGYIUOIUIPIOIPUOHIYGUYFGIH
lecture5.pptxJHKGJFHDGTFGYIUOIUIPIOIPUOHIYGUYFGIH
Abodahab
 
Level 1-Safety.pptx Presentation of Electrical Safety
Level 1-Safety.pptx Presentation of Electrical SafetyLevel 1-Safety.pptx Presentation of Electrical Safety
Level 1-Safety.pptx Presentation of Electrical Safety
JoseAlbertoCariasDel
 
"Boiler Feed Pump (BFP): Working, Applications, Advantages, and Limitations E...
"Boiler Feed Pump (BFP): Working, Applications, Advantages, and Limitations E..."Boiler Feed Pump (BFP): Working, Applications, Advantages, and Limitations E...
"Boiler Feed Pump (BFP): Working, Applications, Advantages, and Limitations E...
Infopitaara
 
Process Parameter Optimization for Minimizing Springback in Cold Drawing Proc...
Process Parameter Optimization for Minimizing Springback in Cold Drawing Proc...Process Parameter Optimization for Minimizing Springback in Cold Drawing Proc...
Process Parameter Optimization for Minimizing Springback in Cold Drawing Proc...
Journal of Soft Computing in Civil Engineering
 
introduction to machine learining for beginers
introduction to machine learining for beginersintroduction to machine learining for beginers
introduction to machine learining for beginers
JoydebSheet
 
How to use nRF24L01 module with Arduino
How to use nRF24L01 module with ArduinoHow to use nRF24L01 module with Arduino
How to use nRF24L01 module with Arduino
CircuitDigest
 
211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf
211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf
211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf
inmishra17121973
 
Metal alkyne complexes.pptx in chemistry
Metal alkyne complexes.pptx in chemistryMetal alkyne complexes.pptx in chemistry
Metal alkyne complexes.pptx in chemistry
mee23nu
 
15th International Conference on Computer Science, Engineering and Applicatio...
15th International Conference on Computer Science, Engineering and Applicatio...15th International Conference on Computer Science, Engineering and Applicatio...
15th International Conference on Computer Science, Engineering and Applicatio...
IJCSES Journal
 
Data Structures_Introduction to algorithms.pptx
Data Structures_Introduction to algorithms.pptxData Structures_Introduction to algorithms.pptx
Data Structures_Introduction to algorithms.pptx
RushaliDeshmukh2
 
"Feed Water Heaters in Thermal Power Plants: Types, Working, and Efficiency G...
"Feed Water Heaters in Thermal Power Plants: Types, Working, and Efficiency G..."Feed Water Heaters in Thermal Power Plants: Types, Working, and Efficiency G...
"Feed Water Heaters in Thermal Power Plants: Types, Working, and Efficiency G...
Infopitaara
 
Artificial Intelligence introduction.pptx
Artificial Intelligence introduction.pptxArtificial Intelligence introduction.pptx
Artificial Intelligence introduction.pptx
DrMarwaElsherif
 
theory-slides-for react for beginners.pptx
theory-slides-for react for beginners.pptxtheory-slides-for react for beginners.pptx
theory-slides-for react for beginners.pptx
sanchezvanessa7896
 
new ppt artificial intelligence historyyy
new ppt artificial intelligence historyyynew ppt artificial intelligence historyyy
new ppt artificial intelligence historyyy
PianoPianist
 
AI-assisted Software Testing (3-hours tutorial)
AI-assisted Software Testing (3-hours tutorial)AI-assisted Software Testing (3-hours tutorial)
AI-assisted Software Testing (3-hours tutorial)
Vəhid Gəruslu
 
Smart Storage Solutions.pptx for production engineering
Smart Storage Solutions.pptx for production engineeringSmart Storage Solutions.pptx for production engineering
Smart Storage Solutions.pptx for production engineering
rushikeshnavghare94
 
Smart_Storage_Systems_Production_Engineering.pptx
Smart_Storage_Systems_Production_Engineering.pptxSmart_Storage_Systems_Production_Engineering.pptx
Smart_Storage_Systems_Production_Engineering.pptx
rushikeshnavghare94
 
Degree_of_Automation.pdf for Instrumentation and industrial specialist
Degree_of_Automation.pdf for  Instrumentation  and industrial specialistDegree_of_Automation.pdf for  Instrumentation  and industrial specialist
Degree_of_Automation.pdf for Instrumentation and industrial specialist
shreyabhosale19
 
lecture5.pptxJHKGJFHDGTFGYIUOIUIPIOIPUOHIYGUYFGIH
lecture5.pptxJHKGJFHDGTFGYIUOIUIPIOIPUOHIYGUYFGIHlecture5.pptxJHKGJFHDGTFGYIUOIUIPIOIPUOHIYGUYFGIH
lecture5.pptxJHKGJFHDGTFGYIUOIUIPIOIPUOHIYGUYFGIH
Abodahab
 
Level 1-Safety.pptx Presentation of Electrical Safety
Level 1-Safety.pptx Presentation of Electrical SafetyLevel 1-Safety.pptx Presentation of Electrical Safety
Level 1-Safety.pptx Presentation of Electrical Safety
JoseAlbertoCariasDel
 
"Boiler Feed Pump (BFP): Working, Applications, Advantages, and Limitations E...
"Boiler Feed Pump (BFP): Working, Applications, Advantages, and Limitations E..."Boiler Feed Pump (BFP): Working, Applications, Advantages, and Limitations E...
"Boiler Feed Pump (BFP): Working, Applications, Advantages, and Limitations E...
Infopitaara
 
introduction to machine learining for beginers
introduction to machine learining for beginersintroduction to machine learining for beginers
introduction to machine learining for beginers
JoydebSheet
 
How to use nRF24L01 module with Arduino
How to use nRF24L01 module with ArduinoHow to use nRF24L01 module with Arduino
How to use nRF24L01 module with Arduino
CircuitDigest
 
211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf
211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf
211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf
inmishra17121973
 
Metal alkyne complexes.pptx in chemistry
Metal alkyne complexes.pptx in chemistryMetal alkyne complexes.pptx in chemistry
Metal alkyne complexes.pptx in chemistry
mee23nu
 
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