Skip to content

Commit b6042dc

Browse files
committed
🐛 Fixes
1 parent 3a8338b commit b6042dc

File tree

1 file changed

+26
-22
lines changed

1 file changed

+26
-22
lines changed

routes/dutch.js

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -28,30 +28,34 @@ router.get("/", function (req, res) {
2828
headers: {
2929
"User-Agent": rua,
3030
},
31-
}).then(function (response) {
32-
$ = cheerio.load(response.data);
31+
})
32+
.then(function (response) {
33+
$ = cheerio.load(response.data);
3334

34-
if (dutchRandomWord.length > 0) {
35-
dutchRandomWord = [];
36-
}
37-
let post = $("#output > div");
38-
let word = post.find(`div:nth-child(${rand}) > h3`)[0].children[0].data;
39-
let definition = post
40-
.find(`div:nth-child(${rand}) > span`)[0]
41-
.children[0].data.replace("Meaning: ", "");
42-
let pronunciation = pronounce(word);
43-
dutchRandomWord.push({
44-
word: decodeURI(word.charAt(0).toUpperCase() + word.slice(1)),
45-
definition: decodeURI(
46-
definition.charAt(0).toUpperCase() + definition.slice(1)
47-
),
48-
pronunciation: decodeURI(
49-
pronunciation.charAt(0).toUpperCase() + pronunciation.slice(1)
50-
),
35+
if (dutchRandomWord.length > 0) {
36+
dutchRandomWord = [];
37+
}
38+
let post = $("#output > div");
39+
let word = post.find(`div:nth-child(${rand}) > h3`)[0].children[0].data;
40+
let definition = post
41+
.find(`div:nth-child(${rand}) > span`)[0]
42+
.children[0].data.replace("Meaning: ", "");
43+
let pronunciation = pronounce(word);
44+
dutchRandomWord.push({
45+
word: decodeURI(word.charAt(0).toUpperCase() + word.slice(1)),
46+
definition: decodeURI(
47+
definition.charAt(0).toUpperCase() + definition.slice(1)
48+
),
49+
pronunciation: decodeURI(
50+
pronunciation.charAt(0).toUpperCase() + pronunciation.slice(1)
51+
),
52+
});
53+
console.log(dutchRandomWord);
54+
res.send(JSON.stringify(dutchRandomWord, null, 2));
55+
})
56+
.catch((error) => {
57+
console.log(error.response);
5158
});
52-
console.log(dutchRandomWord);
53-
res.send(JSON.stringify(dutchRandomWord, null, 2));
54-
});
5559
});
5660

5761
module.exports = router;

0 commit comments

Comments
 (0)