About Lesson
Basic Assignments
-
Simple Variables
- Task: Declare variables using
let
andconst
to store your name, age, and whether you are a student. - Example:
javascript
let name = "John";
const age = 25;
let isStudent = true;
- Task: Declare variables using
-
Basic Operations
- Task: Declare two variables to store two numbers. Calculate and print the sum, difference, product, and quotient.
- Example:
javascript
let num1 = 10;
let num2 = 5;
console.log(num1 + num2); // Sum
console.log(num1 - num2); // Difference
console.log(num1 * num2); // Product
console.log(num1 / num2); // Quotient
-
String Concatenation
- Task: Create variables to store your first name and last name. Concatenate them to form your full name and print it.
- Example:
javascript
let firstName = "John";
let lastName = "Doe";
let fullName = firstName + " " + lastName;
console.log(fullName);
Intermediate Assignments
-
Array Manipulation
- Task: Create an array to store the names of five friends. Add a new name to the array and remove the last name from the array. Print the updated array.
- Example:
javascript
let friends = ["Alice", "Bob", "Charlie", "David", "Eve"];
friends.push("Frank");
friends.pop();
console.log(friends);
-
Object Creation and Access
- Task: Create an object to store information about a car (make, model, year). Access and print each property of the object.
- Example:
javascript
let car = {
make: "Toyota",
model: "Camry",
year: 2021
};
console.log(car.make);
console.log(car.model);
console.log(car.year);
-
Function Declaration
- Task: Declare a function that takes two numbers as arguments and returns their sum. Call the function with different pairs of numbers and print the results.
- Example:
javascript
function addNumbers(a, b) {
return a + b;
}
console.log(addNumbers(5, 3));
console.log(addNumbers(10, 20));
Advanced Assignments
-
Object Array Manipulation
- Task: Create an array of objects, where each object represents a student with properties: name, age, and grade. Write a function to calculate the average grade of the students.
- Example:
javascript
let students = [
{ name: "Alice", age: 20, grade: 85 },
{ name: "Bob", age: 22, grade: 90 },
{ name: "Charlie", age: 23, grade: 95 }
];
function averageGrade(students) {
let total = 0;
for (let student of students) {
total += student.grade;
}
return total / students.length;
}
console.log(averageGrade(students));
Join the conversation