Skip to content

Commit 3a8338b

Browse files
committed
🐛 Fixes
1 parent d79d3bd commit 3a8338b

File tree

1 file changed

+22
-32
lines changed

1 file changed

+22
-32
lines changed

routes/dutch.js

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

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(function (error) {
57-
if (!error.response) {
58-
console.log("API URL is Missing");
59-
res.json("API URL is Missing");
60-
} else {
61-
console.log("Something Went Wrong - Enter the Correct API URL");
62-
res.json("Something Went Wrong - Enter the Correct API URL");
63-
}
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+
),
6451
});
52+
console.log(dutchRandomWord);
53+
res.send(JSON.stringify(dutchRandomWord, null, 2));
54+
});
6555
});
6656

6757
module.exports = router;

0 commit comments

Comments
 (0)