---
# System prepended metadata

title: Exercises for Session 3

---

# Exercises for Session 3

## Date

1. Get the current year and print it to the console
1. Get the current date in the format "MM/DD/YYYY"

## Math

1. Given the following statistics:
   ```javascript
   const players = [
     {
       name: "Player A",
       age: 22,
       stats: {
         points: 324,
         rebounds: 342,
         assists: 425,
       },
     },
     {
       name: "Player B",
       age: 32,
       stats: {
         points: 341,
         rebounds: 421,
         assists: 325,
       },
     },
     {
       name: "Player C",
       age: 27,
       stats: {
         points: 124,
         rebounds: 542,
         assists: 205,
       },
     },
   ];
   ```
   1. Determine which player is the leader of each category using a `Math` method
   1. Determine which player is the leader of each category _**without**_ using a `Math` method
   1. Determine which player is the youngest using a `Math` method
   1. Determine which player is the youngest _**without**_ using a `Math` method

1. Given the points
   ```javascript
   const p1 = [1.3, 2.1, 8.5];
   const p2 = [0.32, 31.1, 2.5];
   ```
   Calculate the distance between them and print the result to the console using a template literal that indicates the meaning of the value.

## RegExp

1. Create a regular expression that allows you to determine whether an email address is **not** an `@mailinator.com` address.

1. Given a string variable called `password`, create an `if`-`else` chain that tests whether the `password` value complies with the following specification:

   1. It contains at least one lowercase letter
   1. It contains at least one uppercase letter
   1. It contains at least one digit
   1. It contains at least one _non_ alphanumeric character
   1. The whole string has at least 8 characters

   If the condition is met, log the message "Good password" to the console, otherwise, log "Password is too weak".

## Error

1. Given this code snippet:
   ```javascript
   try {
     switch (country) {
       case "Colombia": {
         console.log("Calling code: +57");
       }
       case "USA": {
         console.log("Calling code: +1");
       }
       default: {
       }
     }
   } catch (error) {}
   ```
   1. Modify the `default` case so that it throws a `TypeError` with the message "The country <country> is not supported"
   1. Modify the `catch` statement so that it rethrows using an `AggregateError` whose message says "Unsupported operation" and whose `cause` value is the initial error

## JSON

1. Given the following code:

   ```javascript
   const response = `{
     "token": "057ae82791644bff7b7fbc3db54df7633763a51df816a9c9a80fc5ef90decced"
   }`;

   const authenticatedRequest = {
     headers: {},
     data: {},
   };
   ```

   Modify the `headers` object in `authenticatedRequest` so that it has an `Authorization` key whose value is the token provided by `response`