Q-1. Given a = 25 and b = 4, perform all arithmetic operations and display the results.
var a = 25;
var b = 4;
var c;
c = ("Sum: " + (a + b));
c = ("Difference: " + (a - b));
c = ("Product: " + (a * b));
c = ("Quotient: " + (a / b));
c = ("Remainder: " + (a % b));
Q-2. Write a program that takes two numbers from the user and prints their sum, difference, product, quotient, and
remainder.
no1 = Number(prompt("Enter first number"));
no2 = Number(prompt("Enter second number"));
[Link]("Sum: " + (no1 + no2));
[Link]("Difference: " + (no1 - no2));
[Link]("Product: " + (no1 * no2));
[Link]("Quotient: " + (no1 / no2));
[Link]("Remainder: " + (no1 % no2));
Q-3. What is the output of this expression: (a + b) * c when a = 2, b = 3, c = 4?
Answer: (2 + 3) * 4 = 20
[Link]((a + b) * c);
Q-4. What will be the output of [Link](5 + '5') and [Link](5 - '2')? Explain why.
Answer:
[Link](5 + '5'); // 55 (String concatenation)
[Link](5 - '2'); // 3 (String is converted to number)
Q-5. What is the result of: let x = 10 % 3?
Answer: let x = 10 % 3; // 1
Q-6. What is the output of the following code?
let x = 10;
x += 5; // 15
x *= 2; // 30
[Link](x);
Output: 30
Q-7. Write a program that starts with x = 50 and uses +=, -=, *=, /= operators.
let x = 50;
x += 10; // 60
x -= 5; // 55
x *= 2; // 110
x /= 5; // 22
[Link](x);
Q-8. What will be the value of a after this operation: let a = 20; a %= 7;?
Answer: 6
Q-9. Create a mini calculator that accepts values and modifies them using assignment operators.
let value = Number(prompt("Enter initial value:"));
value += 5;
value -= 2;
value *= 3;
value /= 2;
[Link]("Final value: " + value);
Q-10. Explain the difference between x = x + 10; and x += 10;
let x = 5;
x = x + 10; // 15
x += 10; // Also 15, shorthand version
Q-11. What will be the output of this code?
let a = 5;
[Link](a++); // 5
[Link](a); // 6
Q-12. Difference between prefix and postfix increment operators.
let x = 5;
[Link](++x); // 6
[Link](x++); // 6 (then x becomes 7)
Q-13. What will be the output of this code?
let x = 3;
let y = ++x + x++;
[Link](y); // 8
Q-14. Write a loop that prints numbers from 1 to 10 using ++.
for (let i = 1; i <= 10; i++) {
[Link](i);
Q-15. If let count = 10; count--; count--; count++;, what is the final value of count?
Answer: 9
Q-16. What's the difference between 5 == '5' and 5 === '5'?
Answer: 5 == '5' is true, 5 === '5' is false
Q-17. Predict the output:
let a = 10, b = '10';
[Link](a == b); // true
[Link](a === b); // false
Q-18. Write a program that checks if the user's age is >= 18.
let age = Number(prompt("Enter your age:"));
if (age >= 18) {
[Link]("You are eligible.");
} else {
[Link]("You are not eligible.");
Q-19. Is 10 <= 10 and 10 >= 10 true?
Answer: Yes
Q-20. What will be the result of:
let a = 20, b = 25;
[Link](a != b); // true
Q-21. Check if person can vote (age >= 18 and nationality = 'Indian').
let age = 20;
let nationality = "Indian";
if (age >= 18 && nationality === "Indian") {
[Link]("Eligible to vote");
} else {
[Link]("Not eligible");
Q-22. What are the results of:
true && false => false
false || true => true
!false => true
Q-23. Write a login check.
let user = prompt("Enter username:");
let pass = prompt("Enter password:");
if (user && pass) {
[Link]("Login successful");
} else {
[Link]("Username and password required");
}
Q-24. What will this return?
let x = 5;
[Link](x > 3 && x < 10); // true
[Link](!true || false && true); // false
Q-25. Write a ternary statement for age check.
let age = 17;
let msg = (age >= 18) ? "Eligible" : "Not Eligible";
[Link](msg);
Q-26. What is the output?
let a = 10, b = 20;
let result = (a > b) ? a : b;
[Link](result); // 20
Q-27. Ternary operator for pass/fail.
let marks = 35;
[Link](marks >= 40 ? "Pass" : "Fail");
Q-28. Even or Odd check using ternary.
let x = 5;
let res = (x % 2 == 0) ? 'Even' : 'Odd';
[Link](res); // Odd
Q-29. Grade system using nested ternary.
let marks = 90;
let grade = (marks >= 95) ? 'A' :
(marks >= 65) ? 'B' :
(marks >= 70) ? 'C' : 'Fail';
[Link](grade); // B
Q-30. Output of:
let name = "Rahul";
let msg = "Hello " + name;
[Link](msg); // Hello Rahul
Q-31. What happens when a number and string are combined using +?
Answer: Concatenation. 10 + '5' => "105"
Q-32. Predict the output:
let a = 10;
let b = 20;
let msg = "Sum is " + (a + b);
[Link](msg); // Sum is 30
Q-33. Concatenate first and last name.
let first = "Ravi";
let last = "Kumar";
[Link]("Full Name: " + first + " " + last);
Q-34. Take two string inputs and show greeting.
let fname = prompt("Enter first name:");
let lname = prompt("Enter last name:");
[Link]("Welcome " + fname + " " + lname + "!");