Exercise 1: Basic Math Operations
Create an HTML file that includes JavaScript code to perform basic math operations and display the results in the console. Include addition, subtraction, multiplication, and division. For example:
console.log(5 + 3); // Addition
console.log(10 - 2); // Subtraction
console.log(4 * 6); // Multiplication
console.log(20 / 4); // Division
Exercise 2: Variables and Output
- Declare a variable called
name
and assign your name to it. - Declare a variable called
age
and assign your age to it. - Use
console.log()
to display a message in the console, including the variables you declared. For example:
let name = "John";
let age = 30;
console.log("My name is " + name + " and I am " + age + " years old.");
Exercise 3: Alert and Prompt
- Create an HTML file with a button that, when clicked, displays an alert with a custom message.
- Create another button that, when clicked, prompts the user for their name and then displays a greeting alert using the provided name.
Exercise 4: Using Comments
- Write a JavaScript program that calculates the area of a rectangle. Include comments to explain each step of the calculation.
- Write a JavaScript program that converts temperatures from Fahrenheit to Celsius. Include comments to describe the formula and the conversion process.
Exercise 5: Simple Conditional Statements
- Write a JavaScript program that checks if a number is even or odd. Use conditional statements to display the result.
- Create a program that determines if a user is eligible for voting based on their age. If they are eligible, display a message indicating they can vote. If not, display a message that they cannot vote.