Hey there I am new to javascript.
I am working with a API but can not convert the JSON boolean to YES or NO.
The boolean is at Phone that default is false. So I am trying to return false to "NO"
Here is my code:
function loadCustomer(e) {
const xhr = new XMLHttpRequest();
xhr.open('GET', 'https://jsonplaceholder.typicode.com/todos/1', true);
xhr.onload = function () {
if (this.status === 200) {
// console.log(this.responseText);
const person = JSON.parse(this.responseText);
const output = `
<ol>
<li>ID: ${person.userId}</li>
<li>Name: ${person.id}</li>
<li>Company: ${person.title}</li>
<li>Phone: ${person.completed}
</li>
</ol>
`;
document.getElementById('customer').innerHTML = output;
// console.log(customer.completed);
// if (customer.completed = false) {
// output.innerHTML = 'hey'
// }
}
}
xhr.send();
}
Here is the JSON:
{ "userId": 1, "id": 1, "title": "delectus aut autem", "completed": false }