You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

80 lines
2.3 KiB

## Transform Objects
> Mindful AI mode
### Context
Imagine your favorite robot friend with all its cool features: a type, weight, and operational status.
In JavaScript, we use objects to group these properties together, making it easy to manage and tweak our robot’s settings. Let’s see how we can modify, add, or remove properties in a JavaScript object to make our robot even cooler!
### AI-Powered Learning Techniques
**Contextual Learning Technique:**
This strategy places learning within a real-world or practical context by having the AI relate concepts to scenarios you might encounter in everyday life or your work. It helps you understand the relevance of what you’re learning and how to apply it.
Find the examples across the subject ;)
### Concepts
### Modifying Objects
Let's start with a robot object:
```js
const robot = {
points: 0,
code: "75lai78wn",
};
```
### Adding a New Property
Give your robot a name:
```js
robot.name = "RoboMax";
```
### Changing a Property Value
Boost your robot’s points:
```js
robot.points = 10;
```
### Removing a Property
Remove a property:
```js
robot.code = undefined;
```
#### **`Prompt Example`**:
- "Think about your pet. How would you use an object to keep track of its name, age, and favorite food?"
- "You have a collection of books. How could you use an object to remember the title, author, and how many pages each book has?"
### Instructions
#### Task 1:
Modify the provided `robot` variable:
- Add a `model` property with the string value 'RX-78'.
- Add a `fullName` property that is the joined value of the `brand` and the `model` with a space in between. (`brand` and `model`are already defined in the provided `robot`)
- Add `10` to its `batteryLevel` property.
#### Task 2:
Let's move away from objects a bit, and discover a notion we will use later. `Duplicating a String with Placeholders`!
Declare a variable `duplicate` that repeats the provided variable `sentence`, separated by a comma and a space, and then adds an exclamation mark at the end.
> For example, if `sentence` is "Hello there", we expect "Hello there, Hello there!".
**What a good occasion to apply what you learned in using generative AI and documentations to understand duplicating a string with placeholders! Now you are capable to find the information everywhere;)**