Skip to content

Commit 036e9de

Browse files
authored
Delete exercise 21-24 and add 5 new beginner JavaScript exercises (21-25)
- Exercise 21: Your First Array - Introduction to arrays and indexing - Exercise 22: Array Methods - push, pop, shift, unshift, and length - Exercise 23: Your First Object - Object literals and properties - Exercise 24: For...of Loop - Iterating through arrays and strings - Exercise 25: String Methods - Common string manipulation methods Each exercise includes README (EN/ES), app.js, solution.hide.js, and tests.js
1 parent 7fff941 commit 036e9de

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+893
-691
lines changed

exercises/21-Russian_Roulette/README.es.md

Lines changed: 0 additions & 19 deletions
This file was deleted.

exercises/21-Russian_Roulette/README.md

Lines changed: 0 additions & 19 deletions
This file was deleted.

exercises/21-Russian_Roulette/app.js

Lines changed: 0 additions & 16 deletions
This file was deleted.

exercises/21-Russian_Roulette/solution.hide.js

Lines changed: 0 additions & 18 deletions
This file was deleted.

exercises/21-Russian_Roulette/tests.js

Lines changed: 0 additions & 39 deletions
This file was deleted.
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
---
2+
tutorial: "https://www.youtube.com/watch?v=prIqHDmw5r0"
3+
---
4+
5+
# `21` Tu Primer Array
6+
7+
Un array es una lista de valores. Los arrays son una de las estructuras de datos más importantes en programación porque nos permiten almacenar múltiples valores en una sola variable.
8+
9+
Los arrays se declaran con corchetes `[]` y pueden contener cualquier tipo de dato:
10+
11+
```js
12+
let fruits = ["manzana", "plátano", "naranja"];
13+
let numeros = [1, 2, 3, 4, 5];
14+
let mixto = [1, "hola", true, 3.14];
15+
```
16+
17+
Puedes acceder a cada elemento en un array usando su **índice** (posición). Recuerda que los índices comienzan en `0`:
18+
19+
```js
20+
let fruits = ["manzana", "plátano", "naranja"];
21+
console.log(fruits[0]); // "manzana"
22+
console.log(fruits[1]); // "plátano"
23+
console.log(fruits[2]); // "naranja"
24+
```
25+
26+
## 📝 Instrucciones:
27+
28+
1. Crea un array llamado `colors` con al menos 3 nombres de colores como strings.
29+
2. Usa `console.log()` para imprimir cada color accediendo por su posición de índice.
30+
3. Imprime el array completo en la consola.
31+
32+
## Ejemplo:
33+
34+
```js
35+
let animals = ["perro", "gato", "pájaro"];
36+
console.log(animals[0]); // "perro"
37+
console.log(animals[1]); // "gato"
38+
console.log(animals[2]); // "pájaro"
39+
console.log(animals); // ["perro", "gato", "pájaro"]
40+
```
41+
42+
## 💡 Pista:
43+
44+
+ Recuerda: los índices de arrays comienzan en 0, ¡no en 1!
45+
+ Puedes almacenar cualquier tipo de dato dentro de un array.
46+
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
---
2+
tutorial: "https://www.youtube.com/watch?v=prIqHDmw5r0"
3+
---
4+
5+
# `21` Your First Array
6+
7+
An array is a list of values. Arrays are one of the most important data structures in programming because they allow us to store multiple values in a single variable.
8+
9+
Arrays are declared with square brackets `[]` and can hold any type of data:
10+
11+
```js
12+
let fruits = ["apple", "banana", "orange"];
13+
let numbers = [1, 2, 3, 4, 5];
14+
let mixed = [1, "hello", true, 3.14];
15+
```
16+
17+
You can access each element in an array using its **index** (position). Remember that indices start at `0`:
18+
19+
```js
20+
let fruits = ["apple", "banana", "orange"];
21+
console.log(fruits[0]); // "apple"
22+
console.log(fruits[1]); // "banana"
23+
console.log(fruits[2]); // "orange"
24+
```
25+
26+
## 📝 Instructions:
27+
28+
1. Create an array called `colors` with at least 3 color names as strings.
29+
2. Use `console.log()` to print each color accessing it by its index position.
30+
3. Print the array itself to the console.
31+
32+
## Example:
33+
34+
```js
35+
let animals = ["dog", "cat", "bird"];
36+
console.log(animals[0]); // "dog"
37+
console.log(animals[1]); // "cat"
38+
console.log(animals[2]); // "bird"
39+
console.log(animals); // ["dog", "cat", "bird"]
40+
```
41+
42+
## 💡 Hint:
43+
44+
+ Remember: array indexes start at 0, not 1!
45+
+ You can store any type of data inside an array.
46+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
//Create an array with at least 3 colors
2+
let colors = [];
3+
4+
//access and print each color by its index
5+
6+
//print the array
7+
//your code here
8+
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
//Create an array with at least 3 colors
2+
let colors = ["red", "blue", "green"];
3+
4+
//access and print each color by its index
5+
console.log(colors[0]);
6+
console.log(colors[1]);
7+
console.log(colors[2]);
8+
9+
//print the array
10+
console.log(colors);
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
2+
const fs = require('fs');
3+
const path = require('path');
4+
5+
jest.dontMock('fs');
6+
let _buffer = "";
7+
let _log = console.log;
8+
9+
global.console.log = console.log = jest.fn((text) => _buffer += text + "\n");
10+
11+
describe('Array exercise', function () {
12+
afterEach(() => { jest.resetModules(); });
13+
14+
it('Should have an array called "colors"', function () {
15+
const appPath = path.join(__dirname, './app.js');
16+
const appContent = fs.readFileSync(appPath, 'utf8');
17+
expect(appContent).toMatch(/let\s+colors\s*=\s*\[/);
18+
});
19+
20+
it('Should print at least 3 elements from the colors array', function () {
21+
_buffer = "";
22+
const { colors } = require('./app.js');
23+
const logs = _buffer.trim().split('\n');
24+
expect(logs.length).toBeGreaterThanOrEqual(3);
25+
});
26+
27+
it('Should print the array itself', function () {
28+
_buffer = "";
29+
require('./app.js');
30+
expect(_buffer).toMatch(/,/); // arrays have commas when printed
31+
});
32+
});

0 commit comments

Comments
 (0)