Skip to content

Commit

Permalink
0-starwars_characters.js
Browse files Browse the repository at this point in the history
  • Loading branch information
Ambesawi committed Nov 9, 2023
1 parent ca53575 commit 588ffc8
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions 0x06-starwars_api/0-starwars_characters.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/node
// A script that prints all characters of a Star Wars movie

const request = require('request');

const movie = process.argv[2];
const api = 'https://swapi-api.hbtn.io/api/';
const url = api + 'films/' + movie + '/';
request.get({ url: url }, function (error, response, body) {
if (!error) {
const characters = JSON.parse(body).characters;
order(characters);
}
});

function order (characters) {
if (characters.length > 0) {
request.get({ url: characters.shift() }, function (err, res, body) {
if (!err) {
console.log(JSON.parse(body).name);
order(characters);
}
});
}
}

0 comments on commit 588ffc8

Please sign in to comment.