// 1)Shopping Discount System// You have:// amount// isMember(boolean) // A user buys products worth amount.// if amount ≥ 5000 => 20% discount// if amount ≥ 2000 => 10% discount// otherwise => no discount// members get extra 10% discount// Print final price after discount.letamount=5000;letdiscount=0;isMember=true;if(amount>=5000){discount=isMember?30:20;}elseif(amount>=2000){discount=isMember?20:10;}else{discount=0;}letfinalAmount=amount-(amount*discount/100);console.log(`Final amount to be paid: ${finalAmount} after applying a discount of ${discount}%`);
// 2)Login Access Check// you have:// username// password// isBlocked(boolean)// allow login only if:// username is "admin"// password is "1234"// user is not blocked// otherwise print appropriate message.letusername="admin";letpassword="1234";letisBlocked=false;if(username==="admin"&&password==="1234"&&!isBlocked){console.log("Login successful");}elseif(username==="admin"&&password==="1234"&&!isBlocked){console.log("User is blocked");}elseif(username!=="admin"){console.log("Incorrect username");}elseif(username==="admin"&&password!=="1234"){console.log("Incorrect password");}
// 3)Traffic Signal System// Signal color variable:// red = stop// yellow = get ready// green = go// print action based on color.letsignalColor="Red";if(signalColor.toLowerCase()==="Red".toLowerCase()){console.log("Stop");}elseif(signalColor.toLowerCase()==="Yellow".toLowerCase()){console.log("Get ready");}elseif(signalColor.toLowerCase()==="Green".toLowerCase()){console.log("Go");}else{console.log("Invalid signal color");}
// 4)ATM Withdrawal// User has:// balance// withdrawAmount// Rules:// If withdrawAmount > balance = "Insufficient funds"// If withdrawAmount ≤ 0 = "Invalid amount"// Else => deduct and show remaining balanceletbalance=5000;letWithdrawal=2000;if(Withdrawal>balance){console.log("Insufficient funds")}elseif(Withdrawal<=0)console.log("Invalid amount")else{console.log(`Amount after Withdrawal: ${balance-Withdrawal}`)}
// 5)Mobile Data Usage// User has used data GB out of limit GB.// If usage ≥ 100% = "Limit exceeded"// If usage ≥ 80% => "Warning: nearing limit"// Else = "Usage normal"letdataUsed=80;// in GBif (dataUsed>=100){console.log("Limit exceeded");}elseif (dataUsed>=80){console.log("Warning: nearing limit");}else{console.log("Usage normal");}
// 6)Electricity Bill// Units consumed:// 0-100 => 5/unit// 101-300 => 7/unit// 300+ 10/unit// Calculate total bill.letunitsConsumed=90;letunitPrice=0;if (unitsConsumed>0&&unitsConsumed<=100){unitPrice=5;}elseif (unitsConsumed>=101&&unitsConsumed<=300){unitPrice=7;}elseif (unitsConsumed>=301){unitPrice=10;}console.log(`Total Bill Value is ${unitsConsumed*unitPrice}`);
Top comments (0)
Subscribe
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Top comments (0)