MERN Full Stack File
MERN Full Stack File
1 Write a function that takes two numbers and returns their sum.
Output: 15
Q2: Implement a program that checks whether a given
number is even or odd using conditional statements.
const num = 10;
if (num % 2 === 0) {
console.log("Even");
} else {
console.log("Odd");
}
Output: Even
Q3: Create a function using arrow notation that calculates the
square of a number.
const square = num => num * num;
console.log(square(5));
Output: 25
Q4: Use the map() function to double the values in an array.
const arr = [1, 2, 3, 4];
const doubled = arr.map(num => num * 2);
console.log(doubled);
Output: [2, 4, 6, 8]
Q5: Create an object representing a car with properties like
make, model, and year. Print the car’s details using object
destructuring.
const car = { make: "Toyota", model: "Corolla", year: 2020 };
const { make, model, year } = car;
console.log(`Make: ${make}, Model: ${model}, Year: ${year}`);
Output: 10
Q7: Create a simple webpage and manipulate its DOM using
JavaScript.
<!-- HTML -->
<p id="demo">Hello</p>
<button onclick="changeText()">Click Me</button>
<script>
function changeText() {
document.getElementById("demo").innerHTML = "Text changed!";
}
</script>
app.listen(3000);
app.use(bodyParser.json());
app.listen(3000);
app.listen(3000);
mongoose.connect('mongodb://localhost:27017/testDB');