0% found this document useful (0 votes)
2 views3 pages

JavaScript Lecture Loops Conditions Functions

This lecture covers the basics of JavaScript, focusing on loops, conditional statements, and functions. It provides examples of different types of loops (for, while, do-while) and conditional statements (if, if-else, if-else if-else). The lecture concludes by emphasizing the role of functions in organizing code.

Uploaded by

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

JavaScript Lecture Loops Conditions Functions

This lecture covers the basics of JavaScript, focusing on loops, conditional statements, and functions. It provides examples of different types of loops (for, while, do-while) and conditional statements (if, if-else, if-else if-else). The lecture concludes by emphasizing the role of functions in organizing code.

Uploaded by

saqib razaq
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

JavaScript Lecture: Loops, Conditions, and Functions

Introduction

JavaScript is a programming language used to make web pages interactive. In this lecture,
we will learn about loops, conditional statements, and functions.

Loops in JavaScript

Loops are used to execute a block of code repeatedly.

For Loop Example:

for (let i = 1; i <= 5; i++) {

[Link]("Number: " + i);

While Loop Example:

let i = 1;

while (i <= 5) {

[Link]("Count: " + i);

i++;

Do While Loop Example:

let i = 1;

do {

[Link]("Value: " + i);

i++;
} while (i <= 5);

Conditional Statements

If Statement:

let age = 18;

if (age >= 18) {

[Link]("You are eligible to vote");

If Else Statement:

let number = 5;

if (number % 2 === 0) {

[Link]("Even number");

} else {

[Link]("Odd number");

If Else If Else Statement:

let marks = 75;

if (marks >= 80) {

[Link]("Grade A");

} else if (marks >= 60) {

[Link]("Grade B");

} else if (marks >= 40) {

[Link]("Grade C");
} else {

[Link]("Fail");

Functions in JavaScript

Greet Function Example:

function greet(name) {

[Link]("Hello, " + name + "! Welcome to JavaScript.");

greet("Ali");

greet("Sara");

Summary

Loops repeat code, conditions make decisions, and functions organize code.

You might also like