Skip to content

Commit

Permalink
starwars order correction
Browse files Browse the repository at this point in the history
  • Loading branch information
lynnagidza committed Aug 10, 2023
1 parent c38bb79 commit b8bf030
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 4 deletions.
15 changes: 11 additions & 4 deletions 0x06-starwars_api/0-starwars_characters.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,22 @@ request(url + movieId, function (error, response, body) {
console.log(error);
} else {
const characters = JSON.parse(body).characters;
for (const character of characters) {
printInOrder(characters);
}
}
);

async function printInOrder (characters) {
for (const character of characters) {
await new Promise((resolve, reject) => {
request(character, function (error, response, body) {
if (error) {
console.log(error);
reject(error);
} else {
console.log(JSON.parse(body).name);
resolve();
}
});
}
});
}
}
);
31 changes: 31 additions & 0 deletions 0x06-starwars_api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,36 @@ Write a script that prints all characters of a Star Wars movie:
* You must use the [Star wars API](https://swapi-api.alx-tools.com/)
* You must use the `requests` module

## Usage
Run the script with the Movie ID as the first argument:\
`./0-starwars_characters.js <Movie ID>`

## Example
File name: `0-starwars_characters.js`\
Movie ID: `3`
```sh
$ ./0-starwars_characters.js 3
Luke Skywalker
C-3PO
R2-D2
Darth Vader
Leia Organa
Obi-Wan Kenobi
Chewbacca
Han Solo
Jabba Desilijic Tiure
Wedge Antilles
Yoda
Palpatine
Boba Fett
Lando Calrissian
Ackbar
Mon Mothma
Arvel Crynyd
Wicket Systri Warrick
Nien Nunb
Bib Fortuna
```

## License
This project is licensed under the [MIT License](../LICENSE).

0 comments on commit b8bf030

Please sign in to comment.