Answer the question
In order to leave comments, you need to log in
Why does it return Promise { }?
const fetch = require("node-fetch");
async function gen() {
await fetch( "https://www.reddit.com/r/memes/hot/.json?count=100"
)
.then(res => res.json())
.then(json => {
let postID =
json.data.children[
Math.floor(Math.random() * json.data.children.length)
];
result = {
image: postID.data.url,
category: postID.data.link_flair_text,
caption: postID.data.title,
permalink: postID.data.permalink
};
});
return result;
};
console.log(gen())
Answer the question
In order to leave comments, you need to log in
function gen() {
return fetch( "https://www.reddit.com/r/memes/hot/.json?count=100"
)
.then(res => res.json())
.then(json => {
let postID =
json.data.children[
Math.floor(Math.random() * json.data.children.length)
];
result = {
image: postID.data.url,
category: postID.data.link_flair_text,
caption: postID.data.title,
permalink: postID.data.permalink
};
return result;
});
};
gen().then((e) => {
console.log(e)
})
const fetch = require("node-fetch");
async function gen() {
await fetch("https://www.reddit.com/r/memes/hot/.json?count=100")
.then(res => res.json())
.then(json => {
let postID =
json.data.children[
Math.floor(Math.random() * json.data.children.length)
];
result = {
image: postID.data.url,
category: postID.data.link_flair_text,
caption: postID.data.title,
permalink: postID.data.permalink
};
});
return result;
};
console.log(gen())
const fetch = require("node-fetch");
async function gen() {
const response = await fetch("https://www.reddit.com/r/memes/hot/.json?count=100");
const json = await response.json();
const post = json.data.children[Math.floor(Math.random() * json.data.children.length)];
return {
image: post.data.url,
category: post.data.link_flair_text,
caption: post.data.title,
permalink: post.data.permalink
};
}
gen().then(x=>console.log(x));
If you have already solved the problem with a small amount of code, why do you need a plugin that will take up more space, because. universally solves problems?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question