Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Class notes

Class notes 4310702

Rating
-
Sold
-
Pages
8
Uploaded on
01-03-2025
Written in
2024/2025

Lecture notes of 8 pages for the course 4310702 at UoN (Javascript)

Institution
Course

Content preview

Conditional Statements

Conditional statements are a crucial aspect of programming that allow us to control the flow of

our code based on certain conditions. They help us make decisions and execute different sets of

instructions based on whether a condition is true or false. Conditional statements help us to

automate decision-making processes, respond to user input based upon inputs & conditions,

handle errors, and control the overall flow of the code. Without conditional statements, programs

would be limited to executing a fixed sequence of instructions without any flexibility.


Example:

Let’s consider a scenario where we want to create a program that determines whether a student

has passed or failed an exam based on their score. We can use a conditional statement to check if

the score is above a certain passing threshold. If it is, we display a message saying

“Congratulations! You passed.” Otherwise, we display a message saying “Sorry, you failed.

Better luck next time.”



Types of conditional statements

●​ If Statement

●​ If-Else Statement

●​ Else-If Statement

●​ Switch Statement

●​ Ternary Operator

If Statement

The if statement executes a block of code only if the condition is true.

, Syntax:

if (condition) {

// Code to execute if condition is true

}



Example:

let age = 18;

if (age >= 18) {

console.log("You are eligible for voting");

}

If…Else Statements

If-else statements expand on the basic if statement by providing an alternative block of code to

execute when the condition is false. This allows us to handle different outcomes based on

whether the condition evaluates to true or false. If the condition is true, the code inside the if

block is executed; otherwise, the code inside the else block is executed.

Syntax:

if (condition) {

// code to be executed if the condition is true

} else {

// code to be executed if the condition is false

}

Example:

let age = 16;

Written for

Institution
Course

Document information

Uploaded on
March 1, 2025
Number of pages
8
Written in
2024/2025
Type
Class notes
Professor(s)
W
Contains
All classes

Subjects

$8.49
Get access to the full document:

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Get to know the seller
Seller avatar
smocharingoz

Also available in package deal

Get to know the seller

Seller avatar
smocharingoz
Follow You need to be logged in order to follow users or courses
Sold
-
Member since
1 year
Number of followers
0
Documents
17
Last sold
-

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions