Task 1:
Display the result of multiplying a = 3 by b = 6
Code Solution:
const a = 3;
const b = 6;const multiplicationResult = a * b;console.log("Multiplication Result:", multiplicationResult);
Task 2:
Display the result of calculating half of the sum of a and b
Code Solution:
const a = 3;
const b = 6;
const halfSum = (a + b) / 2;
console.log("Half of the sum:", halfSum);
Task 3:
Find the perimeter and area of a rectangle with sides 6 and 3
Code Solution:
const length = 6;
const width = 3;
const perimeter = 2 * (length + width);
const area = length * width;
console.log("Perimeter:", perimeter);
console.log("Area:", area);
Task 4:
Write a formula that calculates BMI (Body Mass Index), BMI = weight (kg) / height (m) squared. Print the result in the console. Display along with the name in the console.
Code Solution:
// BMI = weight / hight**2
function calculateBMI(weight, height) {
return weight / (height ** 2);
}
const weight = 70; // in kg const height = 1.75; // in meters const bmi = calculateBMI(weight, height);
console.log("BMI:", bmi);
Task 5:
Write a program that allows buying a ticket for an adult movie session only for those who are older than 16 years.
Code Solution:
function buyTicket(age) {
if (age > 16)
{
console.log("You can buy a ticket for the adult session.");
} else {
console.log("You are too young for the adult session.");
}
} // Example usage: const userAge = 18; buyTicket(userAge);