Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

182
Views
Uncaught (in promise) TypeError: Cannot read properties of undefined

I am a newbie in JS and trying to learn how API works. I was trying to fetch a randomuser API data but I'm getting this error "Uncaught (in promise) TypeError: Cannot read properties of undefined"

Here's my code:

const url = 'https://randomuser.me/api/';
const btn = document.getElementById('button');
const output = document.getElementById('output');
btn.addEventListener('click', getData);

function getData(){
        output.innerHTML = "";
        fetch(url).then(function(response){
            return response.json()
        }).then(function (data) {
            console.log(data.results);
            const val= data.results;
                let div = document.createElement('div');
                div.textContent = `${val.name.title} ${val.name.first} ${val.name.last}`;
                let ima = document.createElement('img');
                ima.setAttribute('src', data.results.picture.thumbnail);
                ima.style.display = 'block';
                div.appendChild(ima);
                output.appendChild(div);
          });
    }
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!