1. You are building a login system.
Store username and password in variables
and check whether both are filled.
Input:
let username = "raja";
let password = "ajar000999";
if (username && password)
{
console.log("Login successful!");
}
else
{
console.log("username & Password Invalid");
}
Output:
2. Create variables to store a product’s name, price, and stock. Print a message
like:
"iPhone costs ₹60000 and only 5 left in stock".
Input:
let productName = "iPhone";
let price = 60000;
let stack =5;
console.log(productName+"costs ₹"+price+"and only"+stack+
"left in stock");
Output:
3. Store a student’s marks in 3 subjects and calculate total
Input:
let tamil=100;
let english=50;
let hindi=50;
let total = tamil + english + hindi;
console.log("Total Marks"+total);
Output:
5. Create a variable that stores whether a user is logged in or not and show a
welcome message
Input:
let login = true;
if(login)
{
console.log("Welcome!");
}
Output:
6. An e-commerce website gives a 10% discount. Calculate final price.
Input:
let price = 1000;
let discount = 10;
let finalprice = price-(price*discount/100);
console.log("finalprice = "+finalprice);
Output:
7. Check whether a number is even or odd using operator
Input:
let num = 3;
if (num % 2 == 0) {
console.log(num + " is even");
}
else {
console.log(num + " is odd");
}
Output:






Top comments (0)