Skip to content

Commit 2669167

Browse files
committed
Updates to coding during dry run
1 parent 69ec606 commit 2669167

File tree

2 files changed

+58
-40
lines changed

2 files changed

+58
-40
lines changed

content/guided-workshop/exercises/5-coding.md

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ The shelter wants to add their hours to the webpage for the current day so peopl
2626

2727
GitHub Copilot is a cloud-based service offered for both individuals and businesses. As an individual, you can [sign up for a free trial](https://github.com/github-copilot/signup) of the service. After enrolling you will typically install the extension for your IDE, which is available for [Visual Studio](https://marketplace.visualstudio.com/items?itemName=GitHub.copilotvs), [Visual Studio Code](https://marketplace.visualstudio.com/items?itemName=GitHub.copilot), [NeoVIM](https://github.com/github/copilot.vim#getting-started) and the [JetBrains IDEs](https://plugins.jetbrains.com/plugin/17718-github-copilot). Because we'll be using the [codespace](./3-codespaces.md) you defined in the previous exercise, you won't need to manually install the extension - you did that when you configured the dev container!
2828

29-
> **IMPORTANT:** You can complete this exercise without GitHub Copilot by manually writing the code, or copying and pasting from the [provided solution](./resources/solutions/hours.js).
29+
> **IMPORTANT:** You can complete this exercise without GitHub Copilot by manually writing the code. You can also avoid coding altogether by copying and pasting from the [provided solution](../resources/solutions/Hours.js).
3030
3131
1. If you don't already have access to GitHub Copilot, [sign up for a free trial](https://github.com/github-copilot/signup).
3232
1. In the [previous exercise](./3-codespaces.md) you configured your [devcontainer](https://docs.github.com/en/codespaces/setting-up-your-project-for-codespaces/adding-a-dev-container-configuration/introduction-to-dev-containers) to automatically install the extension for GitHub Copilot, so you're all set and ready to go!
@@ -63,9 +63,17 @@ As we'll be hard-coding the hours, it'll be best to store these as an array of o
6363

6464
After creating the array, we'll need code to store the name of current day, stored in a variable named `today`. Then we can find the current day's hours from `shelterHours`, storing it in a variable named `todayHours`. Finally, we can return some HTML displaying the open and close hours.
6565

66-
## Creating the component with GitHub Copilot
66+
## Working with GitHub Copilot as your AI pair programmer
6767

68-
Let's see how GitHub Copilot can help us quickly create the component.
68+
GitHub Copilot is designed to work with you as you write code and comments. It will see the current context, and generate suggestions for what it believes is the most likely next section of code. You can interact with GitHub Copilot by writing comments describing what you want to create, or by coding like you normally would. In either case, GitHub Copilot will continue to make suggestions.
69+
70+
You always have the ability to accept, reject, or modify any suggestions generated by GitHub Copilot. You may find the generated code isn't quite what you want, or is exactly what you need.
71+
72+
As you work with GitHub Copilot, it's important to remember that as it's built upon AI, it behaves in a probabilistic rather than a deterministic fashion. This means the suggestions offered may be different, even with the same prompts. As you're getting started with GitHub Copilot, you may want to explore some [best practices and use cases](https://github.blog/2023-06-20-how-to-write-better-prompts-for-github-copilot/) to get the most out of the tool.
73+
74+
### Creating the component with GitHub Copilot
75+
76+
Let's see how GitHub Copilot can help us quickly create the component. We're going to start by creating the core structure for the component. We'll then begin coding the array to store the store's hour, and see how GitHub Copilot will offer a suggestion to complete the rest of the objects. We'll then add a couple of comments to describe the necessary logic (getting today's date, finding today's hours, then displaying the results).
6977

7078
1. Return to your open codespace. If you closed the browser window, return to your repository and select **Code** then your codespace.
7179
1. In the **Explorer** window, navigate to **src** > **components**.
@@ -83,15 +91,22 @@ Let's see how GitHub Copilot can help us quickly create the component.
8391
export default Hours;
8492
```
8593

86-
1. Below the comment you added `// add logic`, begin describing the array you wish to create using natural language. You could add a comment which looks like this:
94+
1. Below the comment you added `// add logic`, begin creating the array by pasting the following code:
8795

8896
```javascript
89-
// create an array called shelterHours with objects for shop hours
90-
// each object has a day for the day, open for opening and close for closing
91-
// the hours are Monday - Friday 10:00 to 16:00, and Saturday - Sunday 09:00 to 20:00
97+
const shelterHours = [
98+
{ day: "Monday", open: "10:00", close: "16:00" },
99+
100+
]
92101
```
93102

94-
1. GitHub Copilot **should** begin making code suggestions. These will appear as grey italicized text similar to IntelliSense. To accept the suggestions, you can hit <kbd>Tab</kbd> on your keyboard. Continue to press <kbd>Tab</kbd> until you see the following code generated:
103+
1. Place your cursor at the end of the line which reads `{ day: "Monday", open: "10:00", close: "16:00" },`. Press <kbd>Enter</kbd> (or <kbd>return</kbd> on a Mac). GitHub Copilot **should** suggest objects for the rest of the week!
104+
105+
The suggestions from GitHub Copilot will appear as grey italicized text, similar to [IntelliSense](https://code.visualstudio.com/docs/editor/intellisense).
106+
107+
1. With the suggestion displaying on the screen, press <kbd>Tab</kbd> to accept the suggestion.
108+
109+
1. Modify the code to ensure the hours for Saturday and Sunday are correct. Your code will resemble the following:
95110

96111
```javascript
97112
const shelterHours = [
@@ -105,7 +120,7 @@ Let's see how GitHub Copilot can help us quickly create the component.
105120
];
106121
```
107122

108-
> **IMPORTANT:** As highlighted earlier, GitHub Copilot is AI, meaning it is probabilistic rather than deterministic. The code generated may be different than what appears here. You can make modifications as appropriate, such as adding more information to the comment to describe what you are looking to have created, or updating the generated code.
123+
> **IMPORTANT:** As highlighted earlier, GitHub Copilot is AI, meaning it is probabilistic rather than deterministic. The code generated may be different than what appears here. You can make modifications as appropriate, such as adding a comment to describe what you are looking to create, or updating the generated code.
109124

110125
1. Immediately below the newly created array, add a comment to describe the creation of a variable named `today` to store the long name of today's date:
111126
@@ -134,7 +149,7 @@ Let's see how GitHub Copilot can help us quickly create the component.
134149
1. Finally, ask GitHub Copilot to display today's hours:
135150
136151
```javascript
137-
// display todays hours in a div container with an id of hours
152+
// display today and the hours in an div with an id of hours
138153
```
139154
140155
1. GitHub Copilot will likely suggest the following code line-by-line, which you can accept by pressing <kbd>Tab</kbd>:
@@ -143,18 +158,16 @@ Let's see how GitHub Copilot can help us quickly create the component.
143158
return (
144159
<div id="hours">
145160
<h2>Today's Hours</h2>
146-
<p>{todayHours.day}: {todayHours.open} to {todayHours.close}</p>
161+
<p>{todayHours.day} {todayHours.open} - {todayHours.close}</p>
147162
</div>
148-
);
163+
)
149164
```
150165
151-
1. You can now make any updates you might like to the resulting code. For example, you might want to update `<h1>` to be `<h2>` instead.
152-
153166
> **NOTE:** As highlighted, an example solution is provided for the [Hours.js](../resources/solutions/Hours.js) component.
154167
155168
## Add the Hours component to index.js
156169
157-
Let's finish out our coding by displaying the `Hours` component to **index.js**, which is the homepage.
170+
Let's finish out our coding by displaying the `Hours` component on **index.js**, which is the homepage.
158171

159172
1. In **Explorer**, open **src** > **pages** > **index.js**.
160173
1. Under the comment which reads `// TODO: Import Hours component`, add the following code to import the `Hours` component:
@@ -180,3 +193,8 @@ All developers write code with some form of assistance. This might come from a h
180193
With the code added, it's time to use the GitHub flow to [incorporate your changes into the code base](./6-github-flow.md).
181194

182195
## Resources
196+
197+
- [GitHub Copilot](https://github.com/features/copilot)
198+
- [How to use GitHub Copilot: Prompts, tips, and use cases](https://github.blog/2023-06-20-how-to-write-better-prompts-for-github-copilot/)
199+
- [Getting started with GitHub Copilot](https://docs.github.com/en/copilot/getting-started-with-github-copilot)
200+
- [GitHub Skills - Code with GitHub Copilot](https://github.com/skills/copilot-codespaces-vscode)
Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,32 @@
11
import React from "react";
22

3-
const Hours = () => {
4-
// create an array called shelterHours with objects for shop hours
5-
// each object has a day for the day, open for opening and close for closing
6-
// the hours are Monday - Friday 10:00 to 16:00, and Saturday - Sunday 09:00 to 20:00
7-
const shelterHours = [
8-
{ day: "Monday", open: "10:00", close: "16:00" },
9-
{ day: "Tuesday", open: "10:00", close: "16:00" },
10-
{ day: "Wednesday", open: "10:00", close: "16:00" },
11-
{ day: "Thursday", open: "10:00", close: "16:00" },
12-
{ day: "Friday", open: "10:00", close: "16:00" },
13-
{ day: "Saturday", open: "09:00", close: "20:00" },
14-
{ day: "Sunday", open: "09:00", close: "20:00" }
15-
];
3+
const Hours = () => {
4+
// add logic
165

17-
// get the long day name and store it in a variable named today
18-
const today = new Date().toLocaleDateString("en-US", { weekday: "long" });
6+
const shelterHours = [
7+
{ day: "Monday", open: "10:00", close: "16:00" },
8+
{ day: "Tuesday", open: "10:00", close: "16:00" },
9+
{ day: "Wednesday", open: "10:00", close: "16:00" },
10+
{ day: "Thursday", open: "10:00", close: "16:00" },
11+
{ day: "Friday", open: "10:00", close: "16:00" },
12+
{ day: "Saturday", open: "9:00", close: "20:00" },
13+
{ day: "Sunday", open: "9:00", close: "20:00" },
14+
15+
]
1916

20-
// get today's hours
21-
const todayHours = shelterHours.find(day => day.day === today);
17+
// get the long day name and store it in a variable called today
18+
const today = new Date().toLocaleDateString('en-US', { weekday: 'long' });
2219

23-
// display todays in a div container with an id of hours
24-
return (
25-
<div id="hours">
26-
<h2>Today's Hours</h2>
27-
<p>{todayHours.day}: {todayHours.open} to {todayHours.close}</p>
28-
</div>
29-
);
30-
};
20+
// get today's hours
21+
const todayHours = shelterHours.find((day) => day.day === today);
22+
23+
// display today and the hours in an div with an id of hours
24+
return (
25+
<div id="hours">
26+
<h2>Today's Hours</h2>
27+
<p>{todayHours.day} {todayHours.open} - {todayHours.close}</p>
28+
</div>
29+
)
30+
}
3131

3232
export default Hours;

0 commit comments

Comments
 (0)