0% found this document useful (0 votes)
5 views8 pages

04 - Conditional Statements in JavaScript

The document explains conditional statements in JavaScript, which allow the code to make decisions based on true or false evaluations. It outlines various types of conditional statements, including if, if...else, switch, and ternary operator, and provides several challenges for practical application. The challenges involve user interactions, such as selecting theme colors, finding the smallest number, managing access control, and creating a simple ATM program.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views8 pages

04 - Conditional Statements in JavaScript

The document explains conditional statements in JavaScript, which allow the code to make decisions based on true or false evaluations. It outlines various types of conditional statements, including if, if...else, switch, and ternary operator, and provides several challenges for practical application. The challenges involve user interactions, such as selecting theme colors, finding the smallest number, managing access control, and creating a simple ATM program.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Conditionals In JavaScript:

Use Case:

Solution:
A Conditional statement lets your code make decisions. It checks if something is true or
false, and then runs certain code based on that.

For Example:
"If it's raining, take an umbrella. Otherwise, enjoy the sunshine!"
Different Types of Conditional Statements
1. if Statement
2. if...else Statement
3. if...else if...else (Also called "Else-If Ladder")
4. Nested if Statements
5. switch Statement
6. Ternary Operator [? :] (short form)

1. if Statement

2. if...else Statement
3. if...else if...else (Also called "Else-If Ladder")

4. Nested if Statements
3. Switch Statement

4. Ternary Operator [? :] (short form)


Challenge 1:

Solution:
Challenge 2:

Solution:
Q.1- Give choice to the user to select theme color and set the selected theme color and console it.
Q.2- Find the smallest of three numbers. Numbers are given by the user.
Q.3- Write a program to manage Role-Based Access Control
Given a user role ("admin", "editor", "viewer"):
Admin: full access
Editor: edit access
Viewer: read-only
Any other: no access
Use switch.
Q.4- Check if Number is Divisible by 3 or 5 or Both. Print "Fizz" for multiples of 3,"Buzz" for multiples of 5,
"FizzBuzz" for both.
Q.5- Create a simple calculator. Take two numbers and an operator (+, -, *, /) and calculate the result using switch.
Q.6- Create a simple ATM program.
User can choose:
1. Check Balance
2. Deposit
3. Withdraw
4. Exit
Note that in case of “Deposit” if deposit amount is less than 1Rs produce error otherwise deposit the amount and show
the message with a new balance. And in case of “Withdraw” if withdraw amount is greater than balance then or less
than 1Rs then produce error otherwise withdraw amount and show remaining balance.

You might also like