1)Shopping Discount System:
In online shopping websites, discounts are applied based on the purchase amount.
Rules
Amount ≥ 5000 → 20% discount
Amount ≥ 2000 → 10% discount
Otherwise → No discount
Members get an extra 10% discount
let Amount=5000;
let isMember=true;
let discount=0;
if(Amount>=5000){
discount=0.20;
}else if(Amount>=2000){
discount=.10;
}
if(isMember){
discount=discount+.10;
}
let finalPrice=Amount-(Amount*discount);
console.log("The final Price is "+finalPrice);
O/P: The final Price is 3500
2) Login Access Check:
Username = "admin"
Password = "1234"
User is not blocked
let username="admin";
let password="1234";
let isBlocked=true;
if(username=="admin"){
if(password=="1234"){
if(!isBlocked){
console.log("User verified");
}else{
console.log("User Blocked");
}
}else{
console.log("Not a valid password")
}
}else{
console.log("Not a valid username")
}
O/P: User Blocked
3)Traffic Signal:
Red → Stop
Yellow → Get Ready
Green → Go
let red = "stop";
let yellow = "get ready";
let green = "go";
let colour = "yellow";
switch (colour) {
case "red":
console.log("stop");
break;
case "yellow":
console.log("get ready");
break;
case "green":
console.log("go");
break;
default:
console.log("Enter the Proper signal colour")
}
O/P: get ready
let red = "stop";
let yellow = "get ready";
let green = "go";
let colour = "yellow";
if(colour=="red"){
console.log("stop");
}else if(colour=="yellow"){
console.log("get ready")
}else if(colour=="green"){
console.log("go");
}else{
console.log("Enter the proper colour")
}
O/P: get ready
4) ATM Withdrawal:
If amount > balance → Insufficient funds
If amount ≤ 0 → Invalid amount
Otherwise deduct amount
let UserBalance=5000;
let WithdrawAmount=1000;
let FinalAmount=0;
if(UserBalance>=WithdrawAmount){
FinalAmount=UserBalance-WithdrawAmount;
console.log("Amount withdrawn is "+WithdrawAmount +" and the Final Amount is " +FinalAmount);
}else if(UserBalance<WithdrawAmount){
console.log("Insufficient Fund")
}
O/P: Amount withdrawn is 1000 and the Final Amount is 4000
5) Mobile Data Usage
Internet data usage.
Usage ≥ 100 → Limit exceeded
Usage ≥ 80 → Warning
Otherwise normal usage
let usage=40;
if(usage>=100){
console.log("Limit Exceeded");
}else if(usage>=80){
console.log("Warning: Usage is nearing limit");
}else {
console.log("Normal Usage");
}
O/P: Normal Usage
6) Electricity Bill:
This calculates the bill amount based on units consumed.
0–100 → ₹5/unit
101–300 → ₹7/unit
Above 300 → ₹10/unit
let unitsConsumed=60;
let bill=0;
if(unitsConsumed<=100){
bill=unitsConsumed*5;
}else if(unitsConsumed>100 && unitsConsumed<300){
if(unitsConsumed)
bill=unitsConsumed*7;
}else{
bill=unitsConsumed*10;
}
console.log("Total Bill:"+bill);
O/P: Total Bill:300
Top comments (0)