I need a little help. Getting error obj is undefined.
HTML:
<!DOCTYPE html>
<html>
<head>
<title>rest</title>
</head>
<body>
<ul id="myList">
</ul>
<script>
var obj;
function fetchdata(){
fetch('https://restcountries.eu/rest/v2/?fullText=true')
.then(resp=> resp.json())
.then(success => obj = success);
}
fetchdata();
var obLength = obj.length;
for (i = 0; i < obLength; i++){
var nm = obj[i].name;
if (nm.startsWith("A") && nm.endsWith("a")){
var x = document.createElement("LI");
var t = document.createTextNode(obj[i].name);
x.appendChild(t);
document.getElementById("myList").appendChild(x);
}
}
</script>
</body>
</html>