-2
I am studying pure javascript and api calls. My code is giving this error:
Uncaught (in promise) TypeError: users.forEach is not a function
at renderUsers
async function getUsers() {
let url = 'https://frontend-intern-challenge-api.iurykrieger.now.sh/products?page=1';
try {
let res = await fetch(url);
return await res.json();
} catch (error) {
console.log(error);
}
}
async function renderUsers() {
let users = await getUsers();
let html = '';
users.forEach(user => {
let htmlSegment = `<div class="user">
<img src="${user.image}" >
<h2>${user.name} ${user.description}</h2>
</div>`;
html += htmlSegment;
});
let container = document.querySelector('#mostrar');
container.innerHTML = html;
}
renderUsers();
and html:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<div id="mostrar"></div>
<script src="./api.js"></script>
</body>
</html>
I’m very beginner in programming and here, so I don’t know how and what the correct procedures are. I posted the question because I couldn’t solve the problem.
– lucas-eugenio1990
@Lucas-eugenio1990 Relax, I thought it was the case of being a beginner. My intention was to guide you.
– Giovane
yes and I thank you for the tips...
– lucas-eugenio1990