Scenario 1:
1)Shopping Discount System
Input:
amount
isMember(boolean)
Rules:
1. amount ≥ 5000 => 20% discount
2. amount ≥ 2000 => 10% discount
3. Otherwise, no discount
4. members get extra 10% discount
5. Print final price after discount.
Flow diagram:
Program code
<!DOCTYPE html>
<html>
<title>Shopping task scenario</title>
<head>
<body>
<script>
let amount = 5000;
let ismember = true;
let discount = 0;
if(amount >= 5000)
{
discount = 20;
}
else if(amount >= 2000)
{
discount = 10;
}
else
{
discount = 0;
}
if(ismember)
{
discount = discount + 10;
}
let finalprice = amount - (amount * discount/100)
document.write("Final price concluded" + finalprice)
</script>
</body>
</head>
</html>
Output
Final price concluded3500
Scenario 2
2)Login Access Check
Input
username
password
isBlocked(boolean)
Rules
- Allow login only if:
- username is "Test"
- password is "pwd"
- user is not blocked
- Otherwise print an appropriate message.
Flow diagram
Program code
<!DOCTYPE html>
<html>
<head>
<title>Login access scenario</title>
</head>
<body>
<script>
let username = "admin";
let password = "1234";
let isblocked = true;
if (username == "Test") {
if (password == "pwd") {
document.write("User is not blocked");
}
else {
document.write("Username is wrong");
}
}
else {
document.write("Password");
}
</script>
</body>
</html>
Output
Password
Scenario 3:
3)Traffic Signal System
Input
Signal color variable:
Rules:
- red = stop
- yellow = get ready
- green = go
Flow diagram
Program code
<!DOCTYPE html>
<html>
<head>
<title>Traffic Signal</title>
</head>
<body>
<script>
let color = "red";
if (color == "red") {
document.write("Stop in signal");
}
else if (color == "yellow") {
document.write("Wait in signal");
}
else {
document.write("Go in the signal");
}
</script>
</body>
</html>
Output
Stop in signal
Scenario 4
ATM Withdrawal
Inputs
- balance
- withdrawAmount
Rules:
- If withdrawAmount > balance = "Insufficient funds"
- If withdrawAmount ≤ 0 = "Invalid amount"
- Else => deduct and show remaining balance
Flow diagram
Program code
<!DOCTYPE html>
<html>
<head>
<title>Withdrawal Scenario</title>
</head>
<body>
<script>
let withdrawAmount = 200;
let balance = 2000;
if (withdrawAmount > balance) {
document.write("Balance is insufficient");
}
else if (withdrawAmount <= 0) {
document.write("Invalid amount");
}
else {
let remainingBalance = balance - withdrawAmount;
document.write(
"Remaining balance calculated: "
+ remainingBalance
);
}
</script>
</body>
</html>
Output
Remaining balance calculated1800
Scenario 5
**Mobile Data Usage
***Inputs*
- User has used data
- Used GB out of the limit GB.
Rules
- If usage ≥ 100% = "Limit exceeded"
- If usage ≥ 80% => "Warning: nearing limit"
- Else = "Usage normal"
Flow diagram
Program code
<!DOCTYPE html>
<html>
<head>
<title>Data Usage</title>
</head>
<body>
<script>
let GB = 80;
if (GB >= 100) {
document.write("Limit exceeded");
}
else if (GB >= 80) {
document.write("Warning: nearing limit");
}
else {
document.write("Usage normal");
}
</script>
</body>
</html>
Output
Warning: nearing limit
Scenario 6
Electricity Bill
Inputs
Units consumed
Rules
- 0-100 => 5/unit
- 101-300 => 7/unit
- 300+ 10/unit
- Calculate the total bill.
Flow diagram
Program code
<!DOCTYPE html>
<html>
<head>
<title>Electricity Bill</title>
</head>
<body>
<script>
let unitsConsumed = 200;
let bill = 0;
if (unitsConsumed <= 100) {
bill = unitsConsumed * 5;
}
else if (unitsConsumed <= 300) {
bill = unitsConsumed * 7;
}
else {
bill = unitsConsumed * 10;
}
document.write("Total bill: " + bill);
</script>
</body>
</html>
Output
Total bill1000
Scenario 7
Student Grade System
Inputs
marks
Rules:
- If marks ≥ 90 → Grade A
- If marks ≥ 75 → Grade B
- If marks ≥ 50 → Grade C
- Otherwise → Fail
- Print the grade.
Flow diagram
Program code
<!DOCTYPE html>
<html>
<head>
<title>Marks Grade</title>
</head>
<body>
<script>
let marks = 65;
if (marks >= 90) {
document.write("Grade A");
}
else if (marks >= 75) {
document.write("Grade B");
}
else if (marks >= 50) {
document.write("Grade C");
}
else {
document.write("Failed");
}
</script>
</body>
</html>
Output
Grade C
Scenario 8
Age Eligibility for Voting
Inputs
age
Rules:
- If age ≥ 18 → Eligible to vote
- Otherwise → Not eligible
- Print eligibility status.
Program code
<!DOCTYPE html>
<html>
<head>
<title>Voting Eligibility</title>
</head>
<body>
<script>
let age = 10;
if (age >= 18) {
document.write("Concern person is eligible for voting");
}
else {
document.write("Concern person is not eligible for voting");
}
</script>
</body>
</html>
Output
Concern person is not eligible for voting
Scenario 9
Password Strength Checker
Input
passwordLength
Rules:
- If length ≥ 12 → Strong password
- If length ≥ 8 → Medium password
- Otherwise → Weak password
- Print password strength.
Program code
<!DOCTYPE html>
<html>
<head>
<title>Password Strength Checker</title>
</head>
<body>
<script>
let passwordLength = 10;
if (passwordLength >= 12) {
document.write("Password strength is strong");
}
else if (passwordLength >= 8) {
document.write("Password strength is medium");
}
else {
document.write("Password strength is weak");
}
</script>
</body>
</html>
Scenario - 10
Movie Ticket Pricing
Inputs
age
Rules:
- If age < 5 → Free ticket
- If age ≤ 18 → Ticket price = 100
- If age ≤ 60 → Ticket price = 150
- Otherwise → Senior citizen price = 120
- Print ticket price.
Program code
<!DOCTYPE html>
<html>
<head>
<title>Movie Ticket Booking</title>
</head>
<body>
<script>
let age = 10;
let ticketFare = 0;
if (age < 5) {
ticketFare = 0;
}
else if (age <= 18) {
ticketFare = 100;
}
else if (age <= 60) {
ticketFare = 150;
}
else {
ticketFare = 120;
}
document.write("The final ticket price is " + ticketFare);
</script>
</body>
</html>
Output
The final ticket price is100
Scenario 11
Temperature Alert System
Inputs
temperature
Rules:
- If temperature ≥ 40 → Heat alert
- If temperature ≥ 30 → Warm weather
- Otherwise → Normal weather
- Print weather status.
Program code
<!DOCTYPE html>
<html>
<head>
<title>Temperature Monitor System</title>
</head>
<body>
<script>
let temperature = 20;
let weather = "";
if (temperature >= 40) {
weather = "Heat alert";
}
else if (temperature >= 30) {
weather = "Warm weather";
}
else {
weather = "Normal";
}
document.write("The weather condition is " + weather);
</script>
</body>
</html>
Output
The wether condition isNormal







Top comments (0)