Reference Material-Conditionals and Loops
Reference Material-Conditionals and Loops
What is an Operator?
❖ Let us take a simple expression: 4 + 5 is equal to 9. Here 4 and 5 are called
operands and ‘+’ is called the operator.
● Assignment Operators
Comparison Operators
3
Decision Making
A conditional/decision-making statement evaluates a condition before the instruction/s is executed.
4
IF STATEMENT
Syntax
if (condition) {
Eg:
num=prompt(‘Enter a number’);
if(num>0){
5
if (condition) {
} else {
Eg:
num=prompt(‘Enter a number’);
if(num>0){
document.write(‘It is a positive
number’);
Else{
6
document.write(‘It is a Negative
number’);
Note: document.write is a function that is used to display some strings in the output
HTML web pages
JavaScript Loops (A way to repeat a set of instructions multiple times)
Loops can execute a block of code a number of times.
The while loop loops through a A For loop repeats until a specified
block of code as long as a specified condition evaluates to false.
condition is true. Syntax
Syntax for(InitialExpression; condition;
updateexpression)
while (condition) { {
//for loop body
// code block to be executed
}
}
Flow Chart
FlowChart