# web-d08 **Repository Path**: professor_baptiste/web-d08 ## Basic Information - **Project Name**: web-d08 - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2025-03-25 - **Last Updated**: 2025-09-10 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # web-d08 JavaScript Exercises for Beginners [Invitation link](https://gitee.com/professor_baptiste/web-d08/invite_link?invite=6955991ca0cc86b6b524b9da4d402fd9127156345fac852ee511b1509403e86e0f878f1f24fab9942fe8257fd1ad0bbe) ## Setup Instructions 1. Create a separate folder for each exercise: - `ex_01` for Exercise 1 - `ex_02` for Exercise 2 - `ex_03` for Exercise 3 - `ex_04` for Exercise 4 - `ex_05` for Exercise 5 2. In each folder, create a file named `script.js` 3. Write your solution in the `script.js` file 4. Run your solution using Node.js: ``` node script.js ``` 5. Verify that your output matches the expected results ## Exercise 1: Variables and Simple Functions **Directory**: `ex_01` **File**: `script.js` **Task**: Create a function that calculates the area of a rectangle using `const` for dimensions and respecting the camelCase convention for variable names. **Documentation Links**: - [JavaScript Variables](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Grammar_and_types#declarations) - [const keyword](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/const) - [JavaScript Functions](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Functions) - [Naming Conventions (camelCase)](https://developer.mozilla.org/en-US/docs/MDN/Writing_guidelines/Writing_style_guide/Code_style_guide/JavaScript#naming_conventions) **Expected Output**: Input: ```javascript calculateRectangleArea(5, 3); ``` Output: ``` 15 ``` Input: ```javascript calculateRectangleArea(7, 2); ``` Output: ``` 14 ``` ## Exercise 2: String Manipulation **Directory**: `ex_02` **File**: `script.js` **Task**: Write a function that takes a first name and a last name, then returns a personalized greeting using template literals (`${}`). **Documentation Links**: - [Template Literals](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals) - [String Methods](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) **Expected Output**: Input: ```javascript createPersonalizedGreeting("John", "Doe"); ``` Output: ``` "Hello, John Doe! Welcome to our JavaScript course." ``` Input: ```javascript createPersonalizedGreeting("Emma", "Smith"); ``` Output: ``` "Hello, Emma Smith! Welcome to our JavaScript course." ``` ## Exercise 3: Conditions and Ternary Operators **Directory**: `ex_03` **File**: `script.js` **Task**: Create a function that checks if a number is positive, negative, or zero, using ternary operators to simplify the code. **Documentation Links**: - [Conditional (ternary) operator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Conditional_Operator) - [Conditional statements](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Control_flow_and_error_handling#conditional_statements) **Expected Output**: Input: ```javascript checkNumberSign(5); ``` Output: ``` "positive" ``` Input: ```javascript checkNumberSign(-3); ``` Output: ``` "negative" ``` Input: ```javascript checkNumberSign(0); ``` Output: ``` "zero" ``` ## Exercise 4: Arrays and Array Methods **Directory**: `ex_04` **File**: `script.js` **Task**: Write a function that filters an array of numbers to keep only the even numbers, using the `filter()` and `map()` methods. **Documentation Links**: - [Arrays](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array) - [Array.prototype.filter()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter) - [Array.prototype.map()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map) **Expected Output**: Input: ```javascript const numbersArray = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; filterAndProcessEvenNumbers(numbersArray); ``` Output: ``` [4, 8, 12, 16, 20] ``` Input: ```javascript filterAndProcessEvenNumbers([3, 6, 9, 12, 15]); ``` Output: ``` [12, 24] ``` ## Exercise 5: Objects and Destructuring **Directory**: `ex_05` **File**: `script.js` **Task**: Create a function that extracts specific properties from an object representing a user, using destructuring. **Documentation Links**: - [Objects](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Working_with_Objects) - [Destructuring assignment](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment) **Expected Output**: Input: ```javascript const userProfile = { id: 1, name: "Alice Johnson", email: "alice@example.com", age: 28, address: "123 Main Street", phoneNumber: "555-123-4567" }; extractUserInfo(userProfile); ``` Output: ``` { name: "Alice Johnson", email: "alice@example.com", age: 28 } ``` Input: ```javascript extractUserInfo({ id: 42, name: "Bob Smith", email: "bob@example.com", age: 35, role: "Developer" }); ``` Output: ``` { name: "Bob Smith", email: "bob@example.com", age: 35 } ``` ## Challenge Your Understanding For each exercise, try to: 1. Understand what the expected output should be 2. Implement your solution in the appropriate `script.js` file 3. Run your code using `node script.js` to verify it works 4. Extend the function with additional features 5. Think about how you could combine concepts from different exercises ## File Structure Example ``` js-exercises/ ├── ex_01/ │ └── script.js ├── ex_02/ │ └── script.js ├── ex_03/ │ └── script.js ├── ex_04/ │ └── script.js └── ex_05/ └── script.js ``` g