DEV Community

Raja B
Raja B

Posted on

Question & Answer

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");
}
Enter fullscreen mode Exit fullscreen mode

Output:

userName and Password

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");

Enter fullscreen mode Exit fullscreen mode

Output:

Store

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);
Enter fullscreen mode Exit fullscreen mode

Output:

total

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!");
}
Enter fullscreen mode Exit fullscreen mode

Output:

Login

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);
Enter fullscreen mode Exit fullscreen mode

Output:

ecom

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");
        }

Enter fullscreen mode Exit fullscreen mode

Output:

oddEven

Top comments (0)