I'm currently exploring content generation through APIs, but I'm facing an issue where the text generated is not aligning properly within the container on the screen.
The main problem lies in getting the card to be centered on the screen with all of its text centered as well. However, the text generated by the API appears only on the left side of the card.
const jokeText = document.querySelector(".joke");
async function fetchJoke() {
const response = await fetch("https://icanhazdadjoke.com", {
headers: {
Accept: 'application/json',
},
});
const joke = response.json();
return joke;
}
async function clickButton() {
const {
joke
} = await fetchJoke();
jokeText.innerText = joke;
}
<link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="2d4f4242595e595f5c47120b151b">[email protected]</a>/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<body class="container bg">
<div class="card row border-primary text-center" style="width: 40rem;">
<img src="../img/meme.jpg" class="card-img-top mx" alt="...">
<div class="card-body">
<h5 class="card-title">Best dad jokes!</h5>
<div class="col-6 joke text-center"></div>
<button class="col-6 btn btn-primary" onclick="clickButton()">Click for a new joke</button>
</div>
</div>
<script src="api.js"></script>
</body>
Thank you in advance!
Aligning the generated API text in center