Skip to content

Commit b36d59a

Browse files
Reorder Scripting test your skills for consistency (mdn#42963)
* reorder Scripting test your skills for consistency * Restructure using dipika suggestion * last few tweaks
1 parent e05034b commit b36d59a

10 files changed

Lines changed: 963 additions & 74 deletions

File tree

files/en-us/learn_web_development/core/scripting/test_your_skills/arrays/index.md

Lines changed: 122 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Watch the embedded scrim, and complete the task on the timeline (the little ghos
2424
> [!NOTE]
2525
> This task is somewhat of a stretch goal, given that it relies on JavaScript features you've not yet explicitly covered during the course. Give it your best shot, and search online for information on anything you are not sure about.
2626
27-
## Task 1
27+
## Arrays 1
2828

2929
This task gives you some basic array practice:
3030

@@ -34,11 +34,11 @@ This task gives you some basic array practice:
3434

3535
<!-- Code shared across examples -->
3636

37-
```html hidden live-sample___arrays-1 live-sample___arrays-2 live-sample___arrays-3 live-sample___arrays-4
37+
```html hidden live-sample___arrays-1 live-sample___arrays-2 live-sample___arrays-3 live-sample___arrays-4 live-sample___arrays-1-finish live-sample___arrays-2-finish live-sample___arrays-3-finish live-sample___arrays-4-finish
3838
<section></section>
3939
```
4040

41-
```css hidden live-sample___arrays-1 live-sample___arrays-2 live-sample___arrays-3 live-sample___arrays-4
41+
```css hidden live-sample___arrays-1 live-sample___arrays-2 live-sample___arrays-3 live-sample___arrays-4 live-sample___arrays-1-finish live-sample___arrays-2-finish live-sample___arrays-3-finish live-sample___arrays-4-finish
4242
* {
4343
box-sizing: border-box;
4444
}
@@ -51,6 +51,12 @@ p {
5151

5252
<!-- Example-specific code -->
5353

54+
The starting point of the task looks like this (nothing is shown yet):
55+
56+
{{ EmbedLiveSample("arrays-1", "100%", 60) }}
57+
58+
Here's the underlying code for this starting point:
59+
5460
```js live-sample___arrays-1
5561
// Add your code here
5662

@@ -62,7 +68,9 @@ para1.textContent = `Array: ${myArray}`;
6268
section.appendChild(para1);
6369
```
6470

65-
{{ EmbedLiveSample("arrays-1", "100%", 60) }}
71+
The updated output should look like this:
72+
73+
{{ EmbedLiveSample("arrays-1-finish", "100%", 60) }}
6674

6775
<details>
6876
<summary>Click here to show the solution</summary>
@@ -81,9 +89,23 @@ myArray.unshift("crocodiles");
8189
// ...
8290
```
8391

92+
```js hidden live-sample___arrays-1-finish
93+
const myArray = ["cats", "dogs", "chickens"];
94+
95+
myArray[0] = "horses";
96+
myArray[1] = "pigs";
97+
98+
myArray.unshift("crocodiles");
99+
100+
const section = document.querySelector("section");
101+
const para1 = document.createElement("p");
102+
para1.textContent = `Array: ${myArray}`;
103+
section.appendChild(para1);
104+
```
105+
84106
</details>
85107

86-
## Task 2
108+
## Arrays 2
87109

88110
Now let's move on to another task. Here you are provided with a string to work with.
89111

@@ -93,6 +115,12 @@ To complete the task:
93115
2. Store the length of the array in a variable called `arrayLength`.
94116
3. Store the last item in the array in a variable called `lastItem`.
95117

118+
The starting point of the task looks like this (nothing is shown yet):
119+
120+
{{ EmbedLiveSample("arrays-2", "100%", 60) }}
121+
122+
Here's the underlying code for this starting point:
123+
96124
```js live-sample___arrays-2
97125
const myString = "Ryu+Ken+Chun-Li+Cammy+Guile+Sakura+Sagat+Juri";
98126

@@ -112,7 +140,9 @@ section.appendChild(para2);
112140
section.appendChild(para3);
113141
```
114142

115-
{{ EmbedLiveSample("arrays-2", "100%", 60) }}
143+
The updated output should look like this:
144+
145+
{{ EmbedLiveSample("arrays-2-finish", "100%", 100) }}
116146

117147
<details>
118148
<summary>Click here to show the solution</summary>
@@ -132,9 +162,27 @@ let lastItem = myArray[arrayLength - 1];
132162
// ...
133163
```
134164

165+
```js hidden live-sample___arrays-2-finish
166+
const myString = "Ryu+Ken+Chun-Li+Cammy+Guile+Sakura+Sagat+Juri";
167+
let myArray = myString.split("+");
168+
let arrayLength = myArray.length;
169+
let lastItem = myArray[arrayLength - 1];
170+
171+
const section = document.querySelector("section");
172+
const para1 = document.createElement("p");
173+
para1.textContent = `Array: ${myArray}`;
174+
const para2 = document.createElement("p");
175+
para2.textContent = `The length of the array is ${arrayLength}.`;
176+
const para3 = document.createElement("p");
177+
para3.textContent = `The last item in the array is "${lastItem}".`;
178+
section.appendChild(para1);
179+
section.appendChild(para2);
180+
section.appendChild(para3);
181+
```
182+
135183
</details>
136184

137-
## Task 3
185+
## Arrays 3
138186

139187
For this array task, we provide you with a starting array, and you will work in somewhat the opposite direction. You need to:
140188

@@ -143,6 +191,12 @@ For this array task, we provide you with a starting array, and you will work in
143191
3. Iterate over each item in the array and add its index number after the name inside parentheses, for example `Ryu (0)`. Note that we don't teach how to do this in the Arrays article, so you'll have to do some research.
144192
4. Finally, join the array items together in a single string called `myString`, with a separator of `"-"`.
145193

194+
The starting point of the task looks like this (nothing is shown yet):
195+
196+
{{ EmbedLiveSample("arrays-3", "100%", 60) }}
197+
198+
Here's the underlying code for this starting point:
199+
146200
```js live-sample___arrays-3
147201
const myArray = [
148202
"Ryu",
@@ -165,7 +219,9 @@ para1.textContent = myString;
165219
section.appendChild(para1);
166220
```
167221

168-
{{ EmbedLiveSample("arrays-3", "100%", 60) }}
222+
The updated output should look like this:
223+
224+
{{ EmbedLiveSample("arrays-3-finish", "100%", 60) }}
169225

170226
<details>
171227
<summary>Click here to show the solution</summary>
@@ -200,9 +256,41 @@ const myString = myArray.join(" - ");
200256
// ...
201257
```
202258

259+
```js hidden live-sample___arrays-3-finish
260+
const myArray = [
261+
"Ryu",
262+
"Ken",
263+
"Chun-Li",
264+
"Cammy",
265+
"Guile",
266+
"Sakura",
267+
"Sagat",
268+
"Juri",
269+
];
270+
271+
myArray.pop();
272+
273+
myArray.push("Zangief");
274+
myArray.push("Ibuki");
275+
276+
myArray.forEach((element, index) => {
277+
const newElement = `${element} (${index})`;
278+
myArray[index] = newElement;
279+
});
280+
281+
const myString = myArray.join(" - ");
282+
283+
// Don't edit the code below here!
284+
285+
const section = document.querySelector("section");
286+
const para1 = document.createElement("p");
287+
para1.textContent = myString;
288+
section.appendChild(para1);
289+
```
290+
203291
</details>
204292

205-
## Task 4
293+
## Arrays 4
206294

207295
For this array task, we provide you with a starting array listing the names of some birds.
208296

@@ -211,7 +299,11 @@ To complete the task:
211299
1. Find the index of the `"Eagles"` item, and use that to remove the `"Eagles"` item.
212300
2. Make a new array from this one, called `eBirds`, that contains only birds from the original array whose names begin with the letter "E". Note that {{jsxref("String.prototype.startsWith()", "startsWith()")}} is a great way to check whether a string starts with a given character.
213301

214-
If it works, you should see `"Emus,Egrets"` appear in the page.
302+
The starting point of the task looks like this (nothing is shown yet):
303+
304+
{{ EmbedLiveSample("arrays-4", "100%", 60) }}
305+
306+
Here's the underlying code for this starting point:
215307

216308
```js live-sample___arrays-4
217309
const birds = ["Parrots", "Falcons", "Eagles", "Emus", "Caracaras", "Egrets"];
@@ -226,7 +318,9 @@ para1.textContent = eBirds;
226318
section.appendChild(para1);
227319
```
228320

229-
{{ EmbedLiveSample("arrays-4", "100%", 60) }}
321+
The updated output should look like this:
322+
323+
{{ EmbedLiveSample("arrays-4-finish", "100%", 60) }}
230324

231325
<details>
232326
<summary>Click here to show the solution</summary>
@@ -248,6 +342,23 @@ const eBirds = birds.filter(startsWithE);
248342
// ...
249343
```
250344

345+
```js hidden live-sample___arrays-4-finish
346+
const birds = ["Parrots", "Falcons", "Eagles", "Emus", "Caracaras", "Egrets"];
347+
348+
const eaglesIndex = birds.indexOf("Eagles");
349+
birds.splice(eaglesIndex, 1);
350+
351+
function startsWithE(bird) {
352+
return bird.startsWith("E");
353+
}
354+
const eBirds = birds.filter(startsWithE);
355+
356+
const section = document.querySelector("section");
357+
const para1 = document.createElement("p");
358+
para1.textContent = eBirds;
359+
section.appendChild(para1);
360+
```
361+
251362
</details>
252363

253364
{{PreviousMenuNext("Learn_web_development/Core/Scripting/Arrays", "Learn_web_development/Core/Scripting/Silly_story_generator", "Learn_web_development/Core/Scripting")}}

0 commit comments

Comments
 (0)