I am trying to create a function that returns true or false depending on the condition, but for some reason, It doesn't return true or false, and when I am trying to print what the function returned it says "undefined". What am I doing wrong? I will appreciate any help!
function get_likes(post_id) {
fetch(`posts/${post_id}`).then(response => response.json()).then(post => {
let user = JSON.parse(document.getElementById('user_id')
.textContent);
if (post.likes.includes(user)) {
return true;
} else {
return false;
}
})
}