is not defined
Здравствуйте. Написал такой код
document.addEventListener('DOMContentLoaded', async function() { let data = []; let datac = []; let p; const articleId = new URLSearchParams(window.location.search); for (p of articleId.values()) { await loadArticle(p); } async function loadArticle(paramId) { let response =await fetch('https://gorest.co.in/public/v2/posts/'+paramId); data = await response.json(); } let h1 = document.createElement('h1'); h1.textContent=data.title; document.body.append(h1); let pBody = document.createElement('p'); pBody.textContent=data.body; document.body.append(pBody); }) getComments(1151); console.log(datac); async function getComments(articleID) { let responsec = await fetch('https://gorest.co.in/public-api/comments?post_id=1151'); datac = await responsec.json(); console.log(dataс); //GET [url]https://gorest.co.in/public-api/comments?post_id=4[/url] } Выдает ошибку article.js:22 Uncaught ReferenceError: datac is not defined at article.js:22:13 article.js:22 article.js:26 Uncaught (in promise) ReferenceError: dataс is not defined at getComments (article.js:26:17) т.е. в 22 строчке кода console.log(datac); ругается что не объявленная переменная, но переменная datac объявлена в строке 3 let datac = []; Подскажите, пожалуйста, в чем проблема. |
Здравствуйте, отформатировал код.
|
Цитата:
Про области видимости переменных слышали? |
Спасибо большое!!
|
Часовой пояс GMT +3, время: 12:42. |