Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CON-3184 Fixing instructions in AI.GO/first-wink #2740

Merged
merged 3 commits into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 31 additions & 22 deletions subjects/AI.GO/first-wink/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Don't worry if things feel a bit challenging—that's part of the process! Just

> We can mention thing you do not know; but by this time, you know what to do! Search for it, ask your peers and use clever prompts ;)

- **You need to continue on the HTML, CSS, JS code you submitted for the exercise `first-move`, but with an empty JavaScript file and do not forget to change the name of the linked files to the name of this exercise!**
- **You need to continue on the HTML, CSS, JS code you submitted for the exercise `first-move`, but with an empty JavaScript file. Do not forget to change the name of the linked files to the name of this exercise as well as following the new instructions!**

### Resources

Expand All @@ -33,12 +33,12 @@ We provide you with some content to get started smoothly, check it out!

#### Task 1:

Let's put a button on the top right corner of the page, that will toggle (close or open) the left eye when clicked.
Let's put a button on the top right corner of the page with the `id` set to "eye-btn", that will toggle (close or open) the left eye when clicked.

Add it in the HTML structure:

```js
<button>Click to close the left eye</button>
<button id="eye-btn">Click to close the left eye</button>
```

And add the style in the CSS file:
Expand All @@ -55,53 +55,64 @@ button {

#### Task 2:

Select the button in your JavaScript file that will allow the user to control the robot’s left eye.
Select the button in your JavaScript file by its `id`. That will allow the user to control the robot’s left eye.

```js
// Select the button element using its ID so we can interact with it in our JavaScript

//Example of selecting a button called myButton
const myButton = document.querySelector("button");
//Example of selecting a button called btn-example
const myButton = document.getElementById("btn-example");
```

**`Prompt Example:`**

- "How do I use `querySelector` to select an HTML element by its ID?"
- "How do I use `getElementById` to select an HTML element by its ID?"

#### Task 3:

Write a function that will be triggered when the button is clicked.

This function will make the robot "wink" by toggling the `eye-closed` class on the left eye and change the `button` text based on the current state of the eye.

- It changes the text content of the button: if the eye is open, write "Click to close the left eye", if the eye is closed, write "Click to open the left eye".
1- It changes the text content of the button: if the eye is open, write "Click to close the left eye", if the eye is closed, write "Click to open the left eye".

- It toggles the class eye-closed in the `classList` of the eye-left HTML element.
2- It toggles the class `eye-closed` in the `classList` of the `eye-left` HTML element.

It changes the background color of the eye-left: if the eye is open, to "red", if the eye is closed, to "black"
3- It changes the background color of the `eye-left`: if the eye is open, to "red", if the eye is closed, to "black"

**Code Example:**

```js
const button = document.querySelector('button')
const button = document.getElementById('eye-btn')

const handleClick = (event) => {

// Select the left eye element by its ID
const myDiv = ...
// Select left eye by its ID and assign it to the variable eyeLeft
const eyeLeft = ...

// Check if the eye is currently closed by looking at its background color
// Check if the eye is currently closed by looking at the eyeLeft background color, if it's 'black', that means it's closed.
if (...) {
// If the eye is closed, open it and update the button text
/*
- Add to the 'button' element the text: "Click to close the left eye"
- Change the 'eyeLeft' element background color to red
*/

} else {
// If the eye is open, close it and update the button text
/*
If the eye is open:
- Add to the 'button' element the text: "Click to open the left eye"
- Change the 'eyeLeft' element background color to black
*/
}
// Toggle the 'eye-closed' class on the 'eye-left' div
eyeLeft.classList.toggle("eye-closed")
};

// register the event:
/* Register the event:
here we ask the button to call our `handleClick` function
on the 'click' event, so every time it's clicked
*/
button.addEventListener('click', handleClick)
// here we ask the button to call our `handleClick` function
// on the 'click' event, so every time it's clicked
```

### Expected result
Expand All @@ -110,8 +121,6 @@ You can see an example of the expected result [here](https://youtu.be/IQ6-3X3JBs

**`Prompt Examples:`**

- "As a beginner, explain to me what is `querySelector` in JavaScript, and how do I use it to select an HTML element by its ID or class?"

- "As a beginner, explain to me how can I change the text content of an `HTML element` using JavaScript?"
- "As a beginner, explain to me how can I change the text content and the background color of an `HTML element` using JavaScript?"

- "As a beginner, explain to me how do I use `addEventListener` to make a button respond to a click event in JavaScript?"
2 changes: 1 addition & 1 deletion subjects/AI.GO/the-skeleton/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ We provide you with some content to get started smoothly, check it out!
- Video [Basic set up of an HTML page](https://www.youtube.com/watch?v=QtKoO7tT-Gg&list=PLHyAJ_GrRtf979iZZ1N3qYMfsPj9PCCrF&index=1)
- Video [Different HTML tags overview](https://www.youtube.com/watch?v=Al-Jzpib8VY&list=PLHyAJ_GrRtf979iZZ1N3qYMfsPj9PCCrF&index=2)

Those videos are accompanying you step by step in each exercise, but if you want to check right away all the notions covered in the quest, you can watch the whole playlist throughout your next exercices[Web - HTML, CSS & DOM JavaScript](https://www.youtube.com/playlist?list=PLHyAJ_GrRtf979iZZ1N3qYMfsPj9PCCrF).
Those videos are accompanying you step by step in each exercise, but if you want to check right away all the notions covered in the quest, you can watch the whole playlist throughout your next exercises[Web - HTML, CSS & DOM JavaScript](https://www.youtube.com/playlist?list=PLHyAJ_GrRtf979iZZ1N3qYMfsPj9PCCrF).

> Your working environment may not be exactly the same as what you see in the videos or documentation, just try to adapt your work according to your research and discoveries.
> Don't be afraid to try!
Expand Down
Loading